<template>
  <div class="page-container">
    <!-- 添加商品 -->
    <el-dialog :visible.sync="dialogVisibleTwo" width="50%" title="添加商品">
      <div>
        <div>
          <el-form :model="productForm" label-width="90px" ref="productForm" :size="size">
            <div class="col-sm-9">
              <el-form-item label="商品名称" prop="chineseName">
                <el-input v-model="productForm.goodsName" auto-complete="off"></el-input>
              </el-form-item>
              <el-form-item label="商品编码" prop="code">
                <el-input v-model="productForm.thirdSpuId" auto-complete="off"></el-input>
              </el-form-item>
            </div>
          </el-form>
          <el-button size="mini" @click="productFormFind()">查询</el-button>
          <el-button size="mini" @click="resetProForm()">重置</el-button>
          <el-button size="mini" @click="addAllProduct()">全部添加</el-button>
        </div>
        <div style="padding-top: 45px;">
          <el-table
            :data="tableDataTwo"
            @selection-change="addSelectionChangeProduct"
            :header-cell-style="tableHeaderColor"
            ref="multipleTable"
            style="width: 100%"
            :row-class-name="tableRowClassName"
            border
            :size="size"
          >
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="thirdSpuId" label="商品编码" align="center"></el-table-column>
            <el-table-column prop="chineseName" label="商品名称" align="center"></el-table-column>
            <el-table-column prop="goodsCategory" label="商品分类" align="center"></el-table-column>
            <el-table-column prop="merchantName" label="商家名称" align="center"></el-table-column>
            <el-table-column prop="storeName" label="店铺名称" align="center"></el-table-column>
            <el-table-column prop="salePriceScope" label="原价（元）" align="center"></el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar" style="padding:10px;" v-if="tableDataTwo.length > 0">
            <el-pagination
              @size-change="producthandleSizeChange"
              @current-change="producthandleCurrentChange"
              :current-page="productForm.start"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="productForm.limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="productListTotal"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="dialogVisibleTwo = false">取消</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="dialogVisibleTwo = false"
          @click="productTableData2Click"
          :loading="productEditLoading"
        >确定</el-button>
      </div>
    </el-dialog>

    <!--审核弹框-->
    <el-dialog
      title="管理员备注"
      width="50%"
      :visible.sync="dialogVisibleAdmin"
      :close-on-click-modal="false"
      @closed="handleClose"
    >
      <el-form :model="adminDataForm" label-width="100%" :size="size" label-position="right" inline>
        <el-form-item>
          <div style="width:100%;">
            <el-input
              type="textarea"
              placeholder="请输入备注"
              v-model="adminDataForm.auditRemark"
            >:rows="4"</el-input>
          </div>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="submitFormAdminNotPass" type="primary">不通过</el-button>
        <el-button :size="size" type="primary" @click.native="submitFormAdmin">通过</el-button>
      </div>
    </el-dialog>

    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;width: 100%;">
      <el-steps :active="active - 1" finish-status="success" simple style="margin-top: 20px">
        <el-step title="1、设置促销规则"></el-step>
        <el-step title="2、选择参与商家/店铺"></el-step>
        <el-step title="3、添加活动商品"></el-step>
        <el-step title="4、提交审核"></el-step>
      </el-steps>
      <!-- 基本信息与活动规则 -->
      <div v-show="active==1" class="content">
        <el-form
          :inline="true"
          :model="filters"
          :rules="filtersRules"
          ref="filters"
          :label-position="labelPosition"
        >
          <div>
            <div class="title">基本设置</div>
            <div class="item">
              <el-row>
                <el-form-item label="促销名称" prop="promName" class="wid">
                  <div style="width:100%;">
                    <input
                      type="text"
                      v-model="filters.promName"
                      placeholder="请输入3-60个字符之间"
                      maxlength="60"
                      minlength="3"
                      class="input"
                      style="width:320px;"
                    />
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="活动时间" prop="SeckillTime" class="wid">
                  <div style="width:100%;">
                    <el-date-picker
                      v-model="filters.SeckillTime"
                      type="datetimerange"
                      range-separator="至"
                      start-placeholder="开始时间"
                      end-placeholder="结束时间"
                      size="mini"
                      format="yyyy-MM-dd HH:mm:ss"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      @change="SeckillTimeChanage"
                      :picker-options="pickerOptions"
                    ></el-date-picker>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="活动标签" prop="labelId" class="wid">
                  <div style="width:100%;">
                    <el-select v-model="filters.labelId" placeholder="请选择" size="mini">
                      <el-option
                        v-for="item in tagList"
                        :key="item.id"
                        :label="item.tagName"
                        :value="item.id"
                      ></el-option>
                    </el-select>
                    <el-button type="primary" size="mini" @click="addtags">添加标签</el-button>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="店铺地区" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.storeArea">
                      <el-radio :label="-1" class="form-radio">全国</el-radio>
                      <!--                      <el-radio :label="6" class="form-radio">省</el-radio>-->
                      <!--                      <el-radio :label="9" class="form-radio">市</el-radio>-->
                    </el-radio-group>
                  </div>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div>
            <div class="title">活动规则</div>
            <div class="item">
              <el-row>
                <el-form-item label="促销类型" prop="frontPromType" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.frontPromType" @change="changeDescriptions">
                      <el-radio :label="12" class="form-radio">第X件Y折</el-radio>
                      <el-radio :label="13" class="form-radio">第X件Y元</el-radio>
                      <el-radio :label="14" class="form-radio">满X件Y折</el-radio>
                    </el-radio-group>
                  </div>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="是否叠加应用" prop="overlayAppFlag" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.overlayAppFlag">
                      <el-radio :label="0" class="form-radio">否（超量：按最高层级享受优惠）</el-radio>
                      <el-radio :label="1" class="form-radio">是（倍量：每满一级优惠一次）</el-radio>
                    </el-radio-group>
                    <span v-if="filters.overlayAppFlag == 1">,上限</span>
                    <el-input
                      size="mini"
                      style="width:100px"
                      v-model="filters.overlayAppNum"
                      v-if="filters.overlayAppFlag == 1"
                      type="number"
                    ></el-input>
                    <span v-if="filters.overlayAppFlag == 1">次</span>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="优惠设置" class="wid" prop="promotionRules">
                  <div style="width:100%;">
                    <el-table :data="filters.promotionRules" style="width:1200px">
                      <el-table-column
                        label="优惠阶梯"
                        prop="ladder"
                        width="100%"
                        type="index"
                        :index="indexMethod"
                      ></el-table-column>
                      <el-table-column prop="content" label="优惠门槛">
                        <template slot-scope="scope">
                          <el-form-item>
                            <el-form-item
                              :prop="'promotionRules.' + scope.$index + '.conditionValue'"
                              :rules="filtersRules.conditionValue"
                            >
                              <span
                                v-if="filters.frontPromType == 12 || filters.frontPromType == 13"
                              >第</span>
                              <span v-if="filters.frontPromType == 14">满</span>
                              <el-input
                                v-model.trim="scope.row.conditionValue"
                                placeholder="X"
                                style="width:100px"
                                oninput="value=value.replace(/[^\d]/g,'')"
                                @input="positiveInteger($event)"
                                maxlength="12"
                              ></el-input>件,
                              <span
                                v-if="filters.frontPromType==12 || filters.frontPromType == 14"
                              >打</span>
                              <span v-if="filters.frontPromType==13">付</span>
                            </el-form-item>
                            <el-form-item
                              :prop="'promotionRules.' + scope.$index + '.contentValue'"
                              :rules="filtersRules.contentValue"
                            >
                              <el-input
                                v-model.trim="scope.row.contentValue"
                                placeholder="Y"
                                style="width:100px"
                              ></el-input>
                              <span v-if="filters.frontPromType==12 || filters.frontPromType==14">折</span>
                              <span v-if="filters.frontPromType==13">元</span>
                            </el-form-item>
                          </el-form-item>
                        </template>
                      </el-table-column>

                      <el-table-column prop="explain" label="优惠说明">
                        <template slot-scope="scope">
                          <label>
                            <span v-if="filters.frontPromType == 14">满</span>
                            <span
                              v-if="filters.frontPromType == 12 || filters.frontPromType == 13"
                            >第</span>
                            <span v-if="scope.row.conditionValue == null">x</span>
                            {{scope.row.conditionValue}}件,
                            <span
                              v-if="filters.frontPromType==12 ||filters.frontPromType == 14"
                            >打</span>
                            <span v-if="filters.frontPromType==13">付</span>
                            <span v-if="scope.row.contentValue == null">y</span>
                            {{scope.row.contentValue}}
                            <span
                              v-if="filters.frontPromType==12  ||  filters.frontPromType==14"
                            >折</span>

                            <span v-if="filters.frontPromType==13">元</span>
                            ;
                          </label>
                        </template>
                      </el-table-column>
                      <el-table-column label="操作">
                        <template slot-scope="scope">
                          <el-button
                            v-if="scope.$index != 0"
                            size="mini"
                            type="danger"
                            @click="removePromotionRuleSet(scope.$index, scope.row)"
                          >删除</el-button>
                        </template>
                      </el-table-column>
                    </el-table>
                    <el-button
                      size="mini"
                      type="primary"
                      icon="el-icon-plus"
                      style=" margin-top: 10px;"
                      @click="addPromotionRuleSet()"
                      :disabled="addDis"
                      v-if="filters.overlayAppFlag != 1"
                    >新增优惠</el-button>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="活动描述" prop="description" class="wid">
                  <label class="col-sm-1 ng-binding">中文</label>
                  <div class="col--sm-4">
                    <el-input
                      type="text"
                      class="form-control mgB10 ng-pristine ng-valid"
                      maxlength="100"
                      v-model="filters.description"
                      :placeholder="descriptions"
                    ></el-input>
                  </div>
                  <div class="col--sm-12">
                    <label class="mgB0 ng-binding">注：非必填字段，不填将显示系统默认文案。自定义输入活动说明后将显示在前台商品详情页中，请认真填写。</label>
                    <a
                      href
                      style="color:blue;text-decoration:underline;"
                      data-toggle="modal"
                      data-target="#custom-width-modal-img"
                    ></a>
                  </div>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div>
            <div class="title">交易规则</div>
            <div class="item">
              <el-row v-if="filters.frontPromType!=19">
                <el-form-item label="是否包邮" prop="parcelsFlag" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.parcelsFlag">
                      <el-radio :label="1" class="form-radio">是</el-radio>
                      <el-radio :label="0" class="form-radio">否</el-radio>
                    </el-radio-group>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="是否分摊" prop="costAllocationFlag" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.costAllocationFlag">
                      <el-radio :label="1" class="form-radio">是</el-radio>
                      <el-radio :label="2" class="form-radio">否</el-radio>
                    </el-radio-group>
                    <div v-if="filters.costAllocationFlag == 1" class="rates">
                      <span v-if="deptType == 0">母平台比例：</span>
                      <el-form-item prop="parentAllocationScale" v-if="deptType == 0">
                        <el-input
                          v-model="filters.parentAllocationScale"
                          auto-complete="off"
                          type="text"
                          :size="size"
                          class="parentPlatformRatio"
                        ></el-input>
                      </el-form-item>
                      <span class="m_r16" v-if="deptType == 0">%</span>
                      <span v-if="deptType == 0 || deptType == 1">子平台比例：</span>
                      <el-form-item prop="childAllocationScale" v-if="deptType == 0 || deptType == 1">
                        <el-input
                          v-model="filters.childAllocationScale"
                          auto-complete="off"
                          type="text"
                          :size="size"
                          class="parentPlatformRatio"
                        ></el-input>
                      </el-form-item>
                      <span class="m_r16" v-if="deptType == 0 || deptType == 1">%</span>
                      <span v-if="deptType == 1 || deptType == 2">商家比例：</span>
                      <el-form-item prop="merchantAllocationScale" v-if="deptType == 1 || deptType == 2">
                        <el-input
                          v-model="filters.merchantAllocationScale"
                          auto-complete="off"
                          type="text"
                          :size="size"
                          class="parentPlatformRatio"
                        ></el-input>
                      </el-form-item>
                      <span class="m_r16" v-if="deptType == 1 || deptType == 2">%</span>
                      <span v-if="deptType == 2 || deptType == 3">店铺比例：</span>
                      <el-form-item prop="storeAllocationScale" v-if="deptType == 2 || deptType == 3">
                        <el-input
                          v-model="filters.storeAllocationScale"
                          auto-complete="off"
                          type="text"
                          :size="size"
                          class="parentPlatformRatio"
                        ></el-input>
                      </el-form-item>
                      <span class="m_r16" v-if="deptType == 2 || deptType == 3">%</span>
                    </div>
                  </div>
                </el-form-item>
              </el-row>
            </div>
          </div>

          <div>
            <div class="title">参与条件</div>
            <div class="item">
              <el-row v-if="deptType == 0">
                <el-form-item label="使用渠道" class="wid" required>
                  <div style="width:100%;">
                    <el-tree
                      :data="channelList"
                      :props="channlProps"
                      show-checkbox
                      node-key="id"
                      ref="channelTree"
                      :default-checked-keys="checkall"
                      :default-expand-all="true"
                    ></el-tree>
                  </div>
                </el-form-item>
              </el-row>

              <el-row>
                <el-form-item label="新老用户" prop="proUserType" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.proUserType">
                      <el-radio
                        v-for="city in proUserTypeRadios"
                        :label="city.code"
                        :key="city.code"
                      >{{city.name}}</el-radio>
                    </el-radio-group>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="用户地区" class="wid">
                  <div style="width:100%;">
                    <el-radio-group v-model="filters.userArea">
                      <el-radio :label="-1" class="form-radio">全国</el-radio>
                    </el-radio-group>
                  </div>
                </el-form-item>
              </el-row>
              <el-row>
                <el-form-item label="备注" class="wid">
                  <el-input
                    type="textarea"
                    v-model="filters.remark"
                    @input="changeRemark($event)"
                    placeholder="请填写备注"
                  ></el-input>
                </el-form-item>
              </el-row>
            </div>
          </div>
        </el-form>
      </div>
      <!--商家店铺列表-->
      <div class="tab-container" v-show="active==2">
        <el-tabs type="border-card" style="margin-top: 15px;">
          <el-tab-pane label="商家">
            <el-row>
              <div style="float: left;margin-bottom: 10px;" v-if="this.auth =='0'">
                <el-button type="primary" size="mini" @click="querySupplierListForAdd()">添加商家</el-button>
                <el-button
                  type="danger"
                  size="mini"
                  @click="delAllSelectedSuppliermerchantTableData2()"
                >批量删除</el-button>
                <el-button
                  type="primary"
                  size="mini"
                  @click="searchMerchantFlag = !searchMerchantFlag"
                >搜索</el-button>
              </div>
            </el-row>
            <el-row>
              <div v-if="searchMerchantFlag">
                <el-form
                  :inline="true"
                  :model="merchantSearchForm"
                  size="mini"
                  ref="merchantSearchForm"
                >
                  <!--                    merchantTableData2-->
                  <el-form-item label="商家编码" prop="orgNumber">
                    <el-input v-model="merchantSearchForm.orgNumber"></el-input>
                  </el-form-item>
                  <el-form-item label="商家名称" prop="merchantName">
                    <el-input
                      v-model="merchantSearchForm.merchantName"
                      @input="changeRemark($event)"
                    ></el-input>
                  </el-form-item>

                  <el-form-item label prop="mpName" style="margin:1%  50px 0 40%">
                    <el-button size="mini" @click="merchantSearch()">查询</el-button>
                    <el-button size="mini" @click="resetMerchantSearch()">重置</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </el-row>
            <el-table
              :data="merchantTableData2"
              border
              style="width: 100%"
              @selection-change="merchantTableData2selectionChange"
            >
              <el-table-column type="selection"></el-table-column>
              <el-table-column prop="id" label="商品编号">
                <template slot-scope="scope">
                  <span>{{ scope.row.orgNumber}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="name" label="商家名称">
                <template slot-scope="scope">
                  <span>{{ scope.row.name}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="type" label="组织分类">
                <template slot-scope="scope">
                  <!--<span>{{ scope.row.merchantType}}</span>-->
                  <span v-if="scope.row.merchantType =='1'">自营商家</span>
                  <span v-if="scope.row.merchantType =='2'">第三方商户</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" v-if="this.auth =='0'">
                <template slot-scope="scope">
                  <el-button
                    type="text"
                    class="textButton"
                    @click="merchantTableData2delete(scope.row.id)"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!--分页栏-->
            <div class="toolbar" style="padding:10px;">
              <el-pagination
                layout="total, sizes, prev, pager, next, jumper"
                @current-change="mainMerchantRefreshPageRequest"
                :current-page="mainMerchantForm.pageNo"
                :page-size="mainMerchantForm.pageSize"
                :total="mainMerchantTableDataTatol"
                style="float:right;"
                :page-sizes="[10, 20, 30, 40]"
                @size-change="mainMerchantHandleSizeChange"
              ></el-pagination>
            </div>
          </el-tab-pane>

          <el-tab-pane label="店铺">
            <el-row>
              <div style="float: left;margin-bottom: 10px;" v-if="this.auth =='0'">
                <el-button type="primary" size="mini" @click="querySupplierListForAdd2()">添加店铺</el-button>
                <el-button
                  type="danger"
                  size="mini"
                  @click="delAllSelectedSupplierstoreTableData()"
                >批量删除</el-button>
                <el-button type="primary" size="mini" @click="searchStoreFlag = !searchStoreFlag">搜索</el-button>
              </div>
            </el-row>
            <el-row>
              <div v-if="searchStoreFlag">
                <el-form :inline="true" :model="storeSearchForm" size="mini" ref="storeSearchForm">
                  <!--                    merchantTableData2-->
                  <el-form-item label="店铺编码" prop="storecode">
                    <el-input v-model.trim="storeSearchForm.storecode"></el-input>
                  </el-form-item>
                  <el-form-item label="店铺名称" prop="storeName">
                    <el-input
                      v-model.trim="storeSearchForm.storeName"
                      @input="changeRemark($event)"
                    ></el-input>
                  </el-form-item>
                  <el-form-item label prop="mpName">
                    <el-button size="mini" @click="storeSearch()">查询</el-button>
                    <el-button size="mini" @click="resetStoreSearch()">重置</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </el-row>
            <el-table
              :data="storeTableData"
              border
              style="width: 100%"
              @selection-change="storeTableDataselectionChange"
            >
              <el-table-column type="selection"></el-table-column>
              <el-table-column label="店铺编号">
                <template slot-scope="scope">
                  <span>{{ scope.row.storecode}}</span>
                </template>
              </el-table-column>
              <el-table-column label="店铺名称">
                <template slot-scope="scope">
                  <span>{{ scope.row.storename}}</span>
                </template>
              </el-table-column>
              <el-table-column label="店铺类型">
                <template slot-scope="scope">
                  <span v-if="scope.row.storeType =='0'">自营店铺</span>
                  <span v-else>加盟店铺</span>
                </template>
              </el-table-column>
              <el-table-column label="操作" v-if="this.auth =='0'">
                <template slot-scope="scope">
                  <el-button type="text" class="textButton" @click="storeDelete(scope.row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!--分页栏-->
            <div class="toolbar" style="padding:10px;">
              <el-pagination
                layout="total, sizes, prev, pager, next, jumper"
                @current-change="mainSroreMerchantRefreshPageRequest"
                :current-page="storeSearchForm.pageNo"
                :page-size="storeSearchForm.pageSize"
                :total="storeTableDataTatol"
                style="float:right;"
                :page-sizes="[10, 20, 30, 40]"
                @size-change="mainSroreMerchantHandleSizeChange"
              ></el-pagination>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>

      <!--促销商品列表-->
      <div v-if="active == 3" class="tab-container">
        <el-tabs type="border-card" @tab-click="handleClickMerchantProduct">
          <el-tab-pane label="添加活动商品">
            <el-form :inline="true" class="demo-form-inline2" size="small">
              <div
                style="display: flex;width: 100%;justify-content : space-between;margin-top: 10px;margin-bottom: 20px;"
              >
                <div>
                  <el-button type="primary" size="mini" @click="addAllProduct">全部添加</el-button>
                  <el-button type="primary" size="mini" @click="add">添加促销商品</el-button>
                  <el-button type="danger" size="mini" @click="batchDelProduct">批量删除</el-button>
                  <!-- <kt-button type="primary" size="mini" :label="alreadyGoodsTotal"></kt-button> -->
                  <el-form :inline="true" class="demo-form-inline2" size="small">
                        <el-button type="primary" size="mini" v-if="alreadyGoodsTotal<=9999">已选商品({{alreadyGoodsTotal}})</el-button>
                        <el-button type="primary" size="mini" v-else>已选商品(9999+)</el-button>
                  </el-form>
                </div>
                <div style="display: flex;">
                  <el-button
                    icon="el-icon-document"
                    size="mini"
                    type="primary"
                    @click="downloadTemplate"
                    style="margin-right: 15px;"
                    v-if="false"
                  >模板下载</el-button>
                  <el-upload
                    class="avatar-uploader"
                    :show-file-list="false"
                    accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
                    v-if="false"
                  >
                    <el-button
                      icon="el-icon-document-add"
                      size="mini"
                      type="primary"
                      v-if="false"
                    >商品导入</el-button>
                  </el-upload>
                  <el-button
                    type="primary"
                    size="mini"
                    @click="searchMerchantProductFlag = !searchMerchantProductFlag"
                  >搜索</el-button>
                </div>
              </div>
            </el-form>
            <el-row>
              <div v-if="searchMerchantProductFlag">
                <el-form
                  :inline="true"
                  :model="merchantProductSearchForm"
                  size="mini"
                  ref="merchantProductSearchForm"
                >
                  <!--                    merchantTableData2-->
                  <el-form-item label="商家">
                    <template>
                      <el-select v-model="merchantProductSearchForm.merchantId" placeholder="请选择">
                        <el-option
                          v-for="item in merchantTableData2"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                        ></el-option>
                      </el-select>
                    </template>
                  </el-form-item>
                  <el-form-item label="商品编码" prop="mpCode">
                    <el-input v-model="merchantProductSearchForm.mpCode"></el-input>
                  </el-form-item>
                  <el-form-item label="商品名称" prop="mpName">
                    <el-input v-model="merchantProductSearchForm.mpName"></el-input>
                  </el-form-item>
                  <el-form-item label="商品分类" prop="categoryName">
                    <el-input v-model="merchantProductSearchForm.categoryName"></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button size="mini" @click="merchantProductSearch()">查询</el-button>
                    <el-button size="mini" @click="resetMerchantProductSearch()">重置</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </el-row>
            <el-table
              :data="merchantProductTableData"
              border
              style="width: 100%"
              :size="size"
              row-key="id"
              default-expand-all
              :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
              @selection-change="repelSelectionChange"
            >
              <el-table-column type="selection" width="55"></el-table-column>
              <el-table-column prop="mpCode" label="商品编码" width="180" align="center"></el-table-column>
              <el-table-column prop="productName" label="商品名称" width="180" sortable align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.mpName}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="categoryName" label="商品分类" width="180" sortable align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.categoryName}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="stock" label="库存" width="180" sortable align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.stock}}</span>
                </template>
              </el-table-column>
              <!--<el-table-column prop="unit" label="计量单位" align="center">-->

              <!--</el-table-column>-->
              <el-table-column prop="merchantName" label="商家名称" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.merchantName}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="storeName" label="店铺名称" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.storeName}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="salePrice" label="零售价（元）" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.salePrice}}</span>
                </template>
              </el-table-column>
              <el-table-column prop="channelMerchantLimit" label="商家单渠道限购" align="center">
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.channelMerchantLimit"
                    @blur="updatePriceOrLimit(scope.row)"
                    :size="size"
                    placeholder="商家单渠道限购"
                    :disabled="scope.row.disabled"
                    oninput="value=value.replace(/[^\d]/g,'')"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="channelStoreLimit" label="店铺单渠道限购" align="center">
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.channelStoreLimit"
                    @blur="updatePriceOrLimit(scope.row)"
                    :size="size"
                    placeholder="店铺单渠道限购"
                    :disabled="scope.row.disabled"
                    oninput="value=value.replace(/[^\d]/g,'')"
                  />
                </template>
              </el-table-column>
              <el-table-column prop="individualLimit" label="个人限购" align="center">
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.individualLimit"
                    @blur="updatePriceOrLimit(scope.row)"
                    :size="size"
                    placeholder="个人限购"
                    :disabled="scope.row.disabled"
                    oninput="value=value.replace(/[^\d]/g,'')"
                  />
                </template>
              </el-table-column>
              <el-table-column label="操作" fixed="right" align="center" width="200">
                <template slot-scope="scope">
                  <el-button
                    @click.native.prevent="delMerchantProducts(scope.row.id)"
                    type="text"
                    size="small"
                  >删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!--分页栏-->
            <div class="toolbar" style="padding:10px;">
              <el-pagination
                @size-change="handleSizeChangeMerchantProduct"
                @current-change="handleCurrentChangeMerchantProduct"
                :current-page="merchantProductSearchForm.start"
                :page-sizes="[10,20,30,40]"
                style="float:right;"
                :page-size="merchantProductSearchForm.limit"
                layout="total, sizes, prev, pager, next, jumper"
                :total="merchantProductTableDataTotal"
              ></el-pagination>
            </div>
          </el-tab-pane>
          <el-tab-pane label="互斥商品" name="1" v-if="false">
            <el-table
              :data="merchantProductTableDataMutex"
              border
              style="width: 100%"
              @selection-change="repelSelectionChange"
            >
              <!--              <el-table-column type="selection" width="55"></el-table-column>-->
              <el-table-column prop="mpCode" label="商品编号" width="180"></el-table-column>
              <el-table-column prop="mpName" label="商品名称" width="180"></el-table-column>
              <el-table-column prop="barcode" label="商品条码"></el-table-column>
              <el-table-column prop="unit" label="计量单位"></el-table-column>
              <el-table-column prop="merchantName" label="商家名称"></el-table-column>
              <el-table-column prop="mutexTime" label="互斥记录时间"></el-table-column>
              <el-table-column prop="markdown" label="操作">
                <template slot-scope="scope">
                  <el-button type="text" class="textButton" @click="seeMore(scope.row)">查看更多</el-button>
                  <el-button type="text" class="textButton" @click="reloadMutexV2(scope.row)">重新添加</el-button>
                </template>
              </el-table-column>
            </el-table>
            <div style="margin-top: 10px;">
              <!--              <el-button size="mini" type="primary" @click="promotionPriceCheckAndSubmit()">确认添加</el-button>-->
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>

      <!-- 活动创建完毕页面 -->
      <div class="tab-container" v-show="active==4">
        <div style="margin-top:10%">
          <img src="/static/images/success.png" style="width:20px;" />
          <span style="font-size:25px;">单品X件活动创建成功!</span>
        </div>
        <div style="margin:40px 0 0 40%; float:left" v-if="shenhe == 0">
          <kt-button
            type="primary"
            plain
            :size="size"
            @click="checkPromotin(0)"
            perms="market:xpiece:submit"
            label="提交审核"
          />
        </div>
        <div style="margin:40px 0 0 40%;float:left" v-if="shenhe == 1">
          <kt-button
            type="primary"
            plain
            :size="size"
            @click="checkPromotin(1)"
            perms="market:xpiece:verify"
            label="审核"
          />
        </div>
        <div style="margin:40px 0 0 40%;float:left" v-if="shenhe != 0 && shenhe !=1"></div>
        <div style="margin-top:40px;float:left;margin-right:10px" v-if="saveTemplateFlag == 0">
          <kt-button
            type="primary"
            plain
            :size="size"
            @click="showSaveTemplate"
            perms="market:xpiece:addtemp"
            label="保存为模板"
          />
        </div>
        <div style="margin-top:40px;float:left;height:30px;line-height:30px">
          <el-link type="primary" @click="detailList">查看活动列表</el-link>
        </div>
      </div>
    </div>
    <div>
      <el-button :size="size" v-if="active != 1 && active != 4" @click="back">上一步</el-button>
      <el-button
        :size="size"
        style="margin-top: 60px;margin-bottom: 60px;"
        @click="next"
        v-show="active!=4"
      >下一步</el-button>
    </div>
    <!-- 选择参与商家 -->
    <el-dialog
      :title="'添加商家'"
      width="45%"
      :visible.sync="editDialogVisible"
      :close-on-click-modal="false"
      @closed="closeMerchant"
    >
      <div>
        <div>
          <el-form :inline="true" :model="merchantForm" size="mini" ref="merchantForm">
            <el-form-item label="商家编号" label-width="100px" prop="orgNumber">
              <el-input v-model.trim="merchantForm.orgNumber" placeholder size="mini"></el-input>
            </el-form-item>
            <el-form-item label="商家名称" label-width="100px" prop="name">
              <el-input v-model.trim="merchantForm.name" placeholder size="mini"></el-input>
            </el-form-item>
          </el-form>
          <el-row style="text-align: left;">
            <el-button size="mini" @click="merchantFormFind()">查询</el-button>
            <el-button size="mini" @click="resetMerForm()">重置</el-button>
          </el-row>
        </div>
        <div style="padding-top: 45px;">
          <el-table
            :data="merchantTableData"
            border
            style="width: 100%"
            @selection-change="addSelectionChange"
            ref="merchantTableData"
          >
            <el-table-column type="selection" width="50px"></el-table-column>
            <el-table-column width="285px" align="center" label="商家编号">
              <template slot-scope="scope">
                <span>{{ scope.row.orgNumber}}</span>
              </template>
            </el-table-column>
            <el-table-column width="389px" align="center" label="商家名称">
              <template slot-scope="scope">
                <span>{{ scope.row.name}}</span>
              </template>
            </el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar" style="padding:10px;" v-if="merchantTableData.length > 0">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              @current-change="refreshPageRequest"
              :current-page="merchantForm.start"
              :page-size="merchantForm.limit"
              :total="merchantTableDataTatol"
              style="float:right;"
              :page-sizes="[10, 20, 30, 40]"
              @size-change="handleSizeChange"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="editDialogVisible = false">取消</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="editDialogVisible = false"
          @click="merchantTableDataSubmit"
        >确定</el-button>
      </div>
    </el-dialog>
    <!-- 选择参与店铺 -->
    <el-dialog
      :title="'添加参与店铺'"
      width="60%"
      :visible.sync="editDialogVisible2"
      :close-on-click-modal="false"
      @closed="closeStore"
    >
      <div>
        <div>
          <el-form :inline="true" :model="storeForm" size="mini">
            <el-form-item label="店铺名称" label-width="100px">
              <el-input v-model.trim="storeForm.storeName" placeholder size="mini"></el-input>
            </el-form-item>
            <el-form-item label="店铺编号" label-width="100px">
              <el-input v-model.trim="storeForm.storeCode" placeholder size="mini"></el-input>
            </el-form-item>
            <el-form-item label="所属商家编号" label-width="100px">
              <el-input v-model.trim="storeForm.orgNumber" placeholder size="mini"></el-input>
            </el-form-item>
            <el-form-item label="所属商家名称" label-width="100px">
              <el-input v-model.trim="storeForm.merchantName" placeholder size="mini"></el-input>
            </el-form-item>
          </el-form>
          <el-row style="text-align: left;padding-left: 32px;">
            <el-button size="mini" @click="storeFormFind()">查询</el-button>
            <el-button size="mini" @click="restStoreForm()">重置</el-button>
          </el-row>
        </div>
        <div style="padding-top: 45px;">
          <el-table
            :data="storeTableData2"
            border
            style="width: 100%"
            @selection-change="storeTableData2AddSelectionChange"
            ref="storeTableData2"
          >
            <el-table-column type="selection"></el-table-column>
            <el-table-column prop="id" label="店铺编号">
              <template slot-scope="scope">
                <span>{{ scope.row.storeCode}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productName" label="店铺名称">
              <template slot-scope="scope">
                <span>{{ scope.row.storeName}}</span>
              </template>
            </el-table-column>
            <el-table-column prop="productName" label="所属商家">
              <template slot-scope="scope">
                <span>{{ scope.row.merchantName}}</span>
              </template>
            </el-table-column>
          </el-table>
          <!--分页栏-->
          <div class="toolbar" style="padding:10px;">
            <el-pagination
              layout="total, sizes, prev, pager, next, jumper"
              @current-change="refreshPageRequestStore"
              :current-page="merchantFormStore.start"
              :page-size="merchantFormStore.limit"
              :total="merchantTableDataTatolStore"
              style="float:right;"
              :page-sizes="[10, 20, 30, 40]"
              @size-change="handleSizeChangeStore"
            ></el-pagination>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="editDialogVisible2 = false">取消</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="editDialogVisible2 = false"
          @click="storeTableData2Click"
        >确定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="添加标签" :visible.sync="addTagDialogFormVisible" width="20%">
      <el-form :model="addTagForm" :rules="addTagRules" ref="addTagForm">
        <el-form-item label="标签分类" :label-width="formLabelWidth" prop="categoryId">
          <el-select
            style="width:200px"
            v-model="addTagForm.categoryId"
            placeholder="请选择分类标签"
            size="mini"
          >
            <el-option
              v-for="(item, index) in tagCategoryList"
              :key="index"
              :label="item.categoryName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="标签名称" :label-width="formLabelWidth" prop="tagName">
          <el-input
            style="width:200px"
            placeholder="请输入标签名称"
            v-model.trim="addTagForm.tagName"
            size="mini"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addTagDialogFormVisible=false" size="mini">取消</el-button>
        <el-button type="primary" @click="addNewTag" size="mini">确定</el-button>
      </div>
    </el-dialog>

    <!--保存模板弹窗-->
    <el-dialog title="保存模板" :visible.sync="saveTemplateDialog" width="20%">
      <el-form :model="saveTemplateForm" :rules="saveTemplateFormRules" ref="saveTemplateForm">
        <el-form-item label="模板名称" :label-width="formLabelWidth" prop="templateName">
          <el-input
            style="width:200px"
            placeholder="请输入模板名称"
            v-model="saveTemplateForm.templateName"
            size="mini"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="saveTemplateDialog=false" size="mini">取消</el-button>
        <el-button type="primary" @click="saveTemplate(0)" size="mini">确定</el-button>
      </div>
    </el-dialog>

    <!-- 新增编辑界面:添加商品 -->
  </div>
</template>

<script>
import { formatDate } from "@/utils/datetime";
import { formatDate2 } from "@/utils/datetime";
import marketRequest from "@/market/request/marketRequest";
import KtButton from "@/views/Core/KtButton";
import { format } from "@/utils/datetime";
import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
import { darkmagenta } from "color-name";
import { quillEditor } from "vue-quill-editor";
import TreeSelect from "@/views/Core/TreeSelect";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import {
  singleFrontPromTypesRadio,
  chanelCodesRadio,
  proPlatformRadio,
  proUserTypeRadio,
  proMemberTypeRadio,
  proMemberLevelRadio
} from "@/market/dict/marketDict";
const channelArr = ["bbc"];
const channelArr1 = ["APP端", "PC端", "微信"];
const channelArr2 = ["新用户", "老用户"];
const channelArr3 = ["普通会员"];
const channelArr4 = ["注册用户", "VIP会员", "金卡"];
export default {
  name: "Tab",
  components: {
    KtButton,
    TableColumnFilterDialog,
    quillEditor,
    TreeSelect
  },
  created: function() {
    this.getTagList();
    // console.log(this.$route.query.auth);
    //当前登录用户身份为母平台才获取子平台列表
    if (this.deptType == 0) {
      this.getChildList();
    }
    
    let _this = this;
    let callback = res => {
      console.log(res);
      if (res.code == "0000") {
        _this.filters.id = res.data.id;
        _this.filters.promType = res.data.promType;
        _this.filters.promName = res.data.promName;
        _this.filters.frontPromType = res.data.frontPromType;
        _this.filters.foldingFlag = res.data.foldingFlag;
        _this.filters.overLimitRule = res.data.overLimitRule;
        _this.filters.description = res.data.description;
        _this.filters.proPlatform = (res.data.proPlatform + "").split("|");
        _this.filters.proUserType = res.data.proUserType + "";
        _this.filters.proMemberType = (res.data.proMemberType + "").split("|");
        _this.filters.proMemberLevel = (res.data.proMemberLevel + "").split(
          "|"
        );
        _this.filters.storeArea = -1; //(res.data.storeArea + "").split("|");
        _this.filters.userArea = -1; //(res.data.userArea + "").split("|");
        _this.filters.startTime = res.data.startTime;
        _this.filters.endTime = res.data.endTime;
        _this.filters.remark = res.data.remark;
        _this.filters.rejectCouponsFlag = res.data.rejectCouponsFlag;
        _this.filters.parcelsFlag = res.data.parcelsFlag;
        _this.filters.promotionRules = res.data.promotionRules;
        _this.filters.mainGiftSameFlag = res.data.mainGiftSameFlag;
        _this.filters.costAllocationFlag = parseInt(
          res.data.costAllocationFlag
        );
        _this.filters.parentAllocationScale = res.data.parentAllocationScale;
        _this.filters.childAllocationScale = res.data.childAllocationScale;
        _this.filters.merchantAllocationScale =
          res.data.merchantAllocationScale;
        _this.filters.storeAllocationScale = res.data.storeAllocationScale;
        _this.filters.templateFlag = res.data.templateFlag;
        _this.filters.templateName = res.data.templateName;
        _this.filters.labelId = parseInt(res.data.labelId);
        _this.filters.overlayAppFlag = res.data.overlayAppFlag;
        _this.filters.freightType = res.data.freightType;
        _this.filters.freightValue = res.data.freightValue;
        _this.filters.freightReducedValue = res.data.freightReducedValue;
        _this.filters.SeckillTime = [res.data.startTime, res.data.endTime];
        //回显使用渠道
        if (
          _this.deptType == 0 &&
          res.data.channelCodes != null &&
          res.data.channelCodes.length > 0
        ) {
          _this.$nextTick(()=>{
            var childreturn = res.data.channelCodes.split(",");
            childreturn = childreturn.map(Number);
            childreturn.forEach(value => {
              _this.$refs.channelTree.setChecked(value, true, false);
            });
          })
          // _this.$refs.channelTree.setCheckedNodes(childreturn)
        }
      } else if (res.code == "9999") {
        _this.$message({ message: "获取促销详情失败", type: "error" });
      }
    };
    if (typeof this.$route.query.active != "undefined") {
      this.promotionId = this.$route.query.value;
      this.active = this.$route.query.active;
    }
    if (typeof this.$route.query.id != "undefined") {
      this.promotionId = this.$route.query.id;
      this.promotion.id = this.$route.query.id;
      //获取促销基本信息详情
      let params = { id: this.promotionId };
      this.utils.request.promotionDetailById(params, callback);
    }
  },
  data() {
    //是否分摊活动验证
    var checkCostAllocationFlag = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请选择是否分摊"));
      } else {
        if (value == 1) {
          var parentAllocationScale = Number(
            this.filters.parentAllocationScale
          ); //母平台分摊比例
          var childAllocationScale = Number(this.filters.childAllocationScale); //子平台分摊比例
          var merchantAllocationScale = Number(
            this.filters.merchantAllocationScale
          ); //商家分摊比例
          var storeAllocationScale = Number(this.filters.storeAllocationScale); //店铺分摊比例
          if (parentAllocationScale == null || parentAllocationScale == "") {
            callback(new Error("请输入母平台分摊比例"));
          } else if (
            childAllocationScale == null ||
            childAllocationScale == ""
          ) {
            callback(new Error("请输入子平台分摊比例"));
          } else if (
            merchantAllocationScale == null ||
            merchantAllocationScale == ""
          ) {
            callback(new Error("请输入商家分摊比例"));
          } else if (
            storeAllocationScale == null ||
            storeAllocationScale == ""
          ) {
            callback(new Error("请输入店铺分摊比例"));
          } else if (
            !Number.isInteger(parentAllocationScale) ||
            !Number.isInteger(childAllocationScale) ||
            !Number.isInteger(merchantAllocationScale) ||
            !Number.isInteger(storeAllocationScale)
          ) {
            callback(new Error("请输入数字值"));
          } else {
            if (
              Number(parentAllocationScale) +
                Number(childAllocationScale) +
                Number(merchantAllocationScale) +
                Number(storeAllocationScale) !=
              100
            ) {
              callback(
                new Error("母平台、子平台、商家、店铺分摊比例总和为100")
              );
            } else {
              callback();
            }
          }
        } else {
          callback();
        }
      }
    };
    var pattern = new RegExp(
      "[`~!@#$^&*()=|{}':;',\\[\\].<>《》/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？ ]"
    );
    var checkPromName = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("请输入活动名称"));
      } else if (value.length < 3 || value.length > 60) {
        return callback(new Error("名称长度在 3 到 60 个字符"));
      } else {
        callback();
      }
    };
    //折扣校验
    var checkConditonValue = (rule, value, callback) => {
      var r = /^\d+\.?\d{0,2}$/; // 2位小数
      // 如果判断不符合正则，则不是正整数不能提交
      if (!r.test(value)) {
        return callback(new Error("请输入数字"));
      } else {
        return callback();
      }
    };
    var checkContentValue = (rule, value, callback) => {
      var reg = /^(?!0(\.0{1,2})?$)(\d(\.\d{1,2})?|10)$/;
      var r = /^\d+\.?\d{0,2}$/; // 2位小数
      if (this.filters.frontPromType == 7 && !reg.test(value)) {
        return callback(new Error("请输入0到10直接的数字(支持2位小数)"));
      }
      if (this.filters.frontPromType == 6 && !r.test(value)) {
        return callback(new Error("请输入数字(支持2位小数)"));
      }
      return callback();
    };
    //时间校验
    var checkSeckillTime = (rule, value, callback) => {
      if (!value || !value[0]) {
        return callback(new Error("请选择活动开始时间"));
      } else if (!value[1]) {
        return callback(new Error("请选择活动结束时间"));
      } else if (value[0] > value[1]) {
        return callback(new Error("活动开始时间不能大于结束时间"));
      } else {
        callback();
      }
    };
    var isNumber = (rule, value, callback)=> {
      if (value === '') {
        return callback();
      }  //这是用来判断如果不是必须输入的，则直接跳出
      const r = /^\+?[1-9][0-9]*$/; // 正整数
      // 如果判断不符合正则，则不是正整数不能提交
      if (!r.test(value)) {
        return callback(new Error('必须为正整数'));
      }else{
        // if (this.filters.parentAllocationScale != undefined
        //   && this.filters.childAllocationScale != undefined
        //   && this.filters.merchantAllocationScale != undefined
        //   && this.filters.storeAllocationScale != undefined){
          let countScale = Number(this.filters.parentAllocationScale) + Number(this.filters.childAllocationScale) + Number(this.filters.merchantAllocationScale) + Number(this.filters.storeAllocationScale);
          console.log(countScale);
          if(countScale != 100){
            return callback(new Error('加起来必须等于100%'));
          }else {
            this.$refs.filters.clearValidate('childAllocationScale');
            this.$refs.filters.clearValidate('merchantAllocationScale');
            this.$refs.filters.clearValidate('storeAllocationScale');
            this.$refs.filters.clearValidate('parentAllocationScale');
            return callback();
          }
        // }
        // return callback();
      }
    };
    return {
      //已选商品
      alreadyGoodsTotal:0,
      //使用渠道全选
      checkall: [],
      //时间控件
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },

      //店铺form表单
      storeSearchForm: {
        promotionId: this.promotionId,
        merchantType: "2",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      //商家form表单
      merchantSearchForm: {
        merchantName: null,
        promotionId: this.promotionId,
        merchantType: "1",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      //商家搜索Tab
      searchMerchantFlag: false,
      //店铺搜索Tab
      searchStoreFlag: false,
      //模板
      saveTemplateFlag: 0,
      //商品编辑框
      merchantProductEditForm: {
        contentValue: null,
        channelMerchantLimit: null,
        channelStoreLimit: null,
        individualLimit: null,
        orderLimit: null
      },
      //商品搜索框
      merchantProductSearchForm: {
        merchantId: null,
        mpCode: null,
        mpName: null,
        goodsCategory: null,
        mpId: null,
        start:1,
        limit:10
      },
      //活动描述
      descriptions: "第X件打Y折",
      //新增优惠是否可编辑
      addDis: false,
      //商品弹窗
      addTagDialogFormVisible: false,
      searchMerchantProductFlag: false,

      //活动模板
      saveTemplateForm: {
        templateName: null
      },
      saveTemplateFormRules: {
        templateName: [
          { required: true, message: "请输入模板名称", trigger: "blur" }
        ]
      },
      saveTemplateDialog: false,
      filtersRules: {
        contentValue: [
          { required: true, validator: checkContentValue, trigger: "change" }
        ],
        conditionValue: [
          { required: true, validator: checkConditonValue, trigger: "change" }
        ],
        saveTemplateForm: {
          templateName: null
        },
        templateDialogVisible: false,
        promName: [
          { required: true, validator: checkPromName, trigger: "blur" }
        ],
        SeckillTime: [
          { required: true, validator: checkSeckillTime, trigger: "blur" }
        ],
        frontPromType: [
          { required: true, message: "请选择促销类型", trigger: "blur" }
        ],
        mainGiftSameFlag: [
          { required: true, message: "请选择赠品类型", trigger: "blur" }
        ],
        overlayAppFlag: [
          { required: true, message: "请选择是否叠加应用", trigger: "blur" }
        ],
        promotionRules: [
          { required: true, message: "请设置优惠设置", trigger: "blur" }
        ],
        parcelsFlag: [
          { required: true, message: "请选择是否包邮", trigger: "blur" }
        ],
        costAllocationFlag: [
          { required: true, message: "请选择是否分摊", trigger: "blur" }
        ],
        channelCodes: [
          { required: true, message: "请选择使用渠道", trigger: "blur" }
        ],
        parentAllocationScale: [
          { required:true,validator:isNumber, trigger: 'blur' }
        ],
        childAllocationScale: [
          { required:true,validator:isNumber, trigger: 'blur' }
        ],
        merchantAllocationScale: [
          { required:true,validator:isNumber, trigger: 'blur' }
        ],
        storeAllocationScale: [
          { required:true,validator:isNumber, trigger: 'blur' }
        ],
        proUserType: [{ required: true, message: "用户类型", trigger: "blur" }]
      },
      mutexDetailDialogVisible: false,
      mutexPromotionTable: [],
      formLabelWidth: "120px",
      tagCategoryList: [
        {
          id: 1,
          categoryName: "标签分类"
        }
      ],
      // setep3--start
      productPromotionListObject: { productPromotionList: [] },
      productAddSelection: [],
      tableDataTwo: [],

      merchantProductTableData: [],
      merchantProductTableDataTotal: 0,
      addTagDialogFormVisible: false,
      addTagForm: {},
      addTagRules: {
        categoryId: [
          { required: true, message: "请选择标签分类", trigger: "change" }
        ],
        tagName: [
          { required: true, message: "请输入标签名称", trigger: "blur" }
        ]
      },
      dialogVisibleTwo: false,
      tabsIndex: "first",
      labelPosition: "right",
      productForm: {
        start: 1,
        limit: 10,
        productName: "",
        productNo: "",
        barCode: "",
        chineseName: "",
        code: ""
      },
      // setep3--end
      adminDataForm: {
        auditRemark: ""
      },
      dialogVisibleAdmin: false,
      shenhe: 0,
      size: "small",
      editDialogVisible: false,
      editDialogVisible2: false,
      url: "./static/shop.png",
      url2: "./static/shop2.png",
      content: null,
      editorOption: {},
      size: "small",
      productVisible: false,
      uploadVisible: false,
      operation: false, // true:商品导入, false:下载模板
      activeName: 0,
      setUp: false,
      search: false,
      tagList: [],
      filters: {
        id: null,
        promType: 7,
        labelId: null,
        promName: null,
        frontPromType: 12,
        foldingFlag: 1,
        overLimitRule: 2,
        channelCodes: null,
        proPlatform: [1],
        proUserType: "0",
        proMemberType: [1],
        proMemberLevel: [2],
        createMerchantId: 11,
        contentType: 1,
        rejectCouponsFlag: 0,
        ruleId: null,
        parcelsFlag: 0,
        overlayAppNumFlag: 0,
        overlayAppNum: null,
        description: "",
        conditionValue: null,
        contentValue: null,
        promotionRules: [
          { conditionValue: null, contentValue: null, id: null, level: 1 }
        ],
        mainGiftSameFlag: 1,
        costAllocationFlag: 1,
        parentAllocationScale: null,
        childAllocationScale: null,
        merchantAllocationScale: null,
        storeAllocationScale: null,
        templateFlag: 1,
        status: 9,
        templateName: null,
        storeArea: -1,
        userArea: -1,
        promotionStartEndTime: [],
        freightType: 1,
        freightValue: null,
        freightReducedValue: null,
        overlayAppFlag: 0,
        SeckillTime: []
      },
      editLoading: false,
  
      dataForm: {},
      modalShow: 1,
      multipleSelection: [],
      batchDeleteSelection: [],
      repelSelection: [],
      addSelection: [],
      businessList: [],
      shopList: [],
      tableData: [],
      active: 1,
      radio1: 3,
      radio2: 3,
      radio3: 3,
      radio4: 3,
      radio5: 3,
      shopList: [],
      businessList: [],
      checkAll: false,
      checkAll1: false,
      checkAll2: false,
      checkAll3: false,
      checkAll4: false,
      checkedCities: [110001],
      checkedCities1: ["APP端", "PC端", "微信"],
      checkedCities2: ["新用户", "老用户"],
      checkedCities3: ["普通会员"],
      checkedCities4: ["注册用户", "VIP会员", "金卡"],
      frontPromTypesRadios: singleFrontPromTypesRadio,
      chanelCodesRadios: chanelCodesRadio,
      proPlatformRadios: proPlatformRadio,
      proUserTypeRadios: proUserTypeRadio,
      proMemberTypeRadios: proMemberTypeRadio,
      proMemberLevelRadios: proMemberLevelRadio,
      cities: channelArr,
      cities1: channelArr1,
      cities2: channelArr2,
      cities3: channelArr3,
      cities4: channelArr4,
      isIndeterminate: true,
      isIndeterminate1: true,
      isIndeterminate2: true,
      isIndeterminate3: true,
      isIndeterminate4: true,
      tagCategoryList: [],
      options: [],
      value5: [],
      options2: [],
      value6: [],
      isClearable: true, // 可清空（可选）
      isAccordion: true, // 可收起（可选）
      valueId: 20, // 初始ID（可选）
      props: {
        // 配置项（必选）
        value: "id",
        label: "name",
        children: "children"
        // disabled:true
      },

      //第一步添加成功赋值
      //外部赋值-----------------start
      promotionId: null,
      auth: 0,
      //外部赋值-----------------start

      promotion: {
        //促销id
        id: "",
        promotionId: "1",
        merchantType: "1"
      },
      pomotionListObject: { pomotionList: [] },

      mainMerchantForm: {
        promotionId: this.promotionId,
        merchantType: "1",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      mainMerchantTableDataTatol: 0,
      //---------------------------商家------------------------------------------------start
      merchantForm: {
        start: 1,
        limit: 10
        // name:"",
        // orgNumber:""
      },
      merchantFormStore: {
        start: 1,
        limit: 10
      },
      merchantTableDataTatol: 0,
      merchantTableDataTatolStore: 0,
      merchantTableData: [],
      //选择的商家列表
      merchantTableData2: [],
      //---------------------------商家------------------------------------------------end
      storeForm: {
        start: 1,
        limit: 10,
        merchantIds: "",
        storename: "",
        storecode: "",
        orgNumber: "",
        merchantName: ""
      },

      mainStoreMerchantForm: {
        promotionId: this.promotionId,
        merchantType: "2",
        pageNo: 1,
        pageSize: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        }
      },
      storeTableDataTatol: 0,
      storeTableData: [],
      //选择店铺
      storeTableData2Tatol: 0,
      storeTableData2: [],
      //选择店铺
      addSelectionStoreTableData2: [],
      merchantTableData2Selection: [],
      merchantTableData2SelectionIndex: 0,
      storeTableDataSelection: [],
      storeTableDataSelectionIndex: 0,

      // -----------------------------------商品开始属性-----------------------------------start

      productTableDataTotal: 0,
      productTableData: [],
      productEditLoading: false,
      productPromotion: {
        //促销id
        promotionId: "1"
      },

      mainProductForm: {
        promotionId: this.promotionId,
        start: 1,
        limit: 10,
        orderBys: {
          f: "create_time",
          s: "desc"
        },
        frontPromType: ""
      },

      merchantProductTableDataMutex: [],

      merchantProductTableDataMutexTotal: 0,
      channelList: [], //渠道Tree List
      channlProps: {
        label: "childName"
      },
      deptType: localStorage.getItem("deptType") //当前登录用户所属组织类型

      // -----------------------------------商品结束属性-----------------------------------end
    };
  },
  methods: {
    //重置商品弹窗
    resetProForm() {
       this.productForm = {}
      this.productForm.start = 1;
      this.productForm.limit = 10
       this.productFormFind();
    },
    //清除复选框
    closeMerchant(row) {
      this.$refs.merchantTableData.clearSelection();
    },
    closeStore() {
      this.$refs.storeTableData2.clearSelection();
    },
    /*
      增加商品 
     */
    addAllProduct() {
      let that_ = this;
      this.productForm.storeIds = this.storeTableData.map((ele, index) => {
        return ele.storeId;
      });
      let callback = function(res) {
        if (res.code == "0000") {
          // 成功查询本地促销商品
          that_.getProductListV2(0, null);
        }
      };
      this.productForm.promotionId = this.filters.id;
      marketRequest.promotionMerchantProductAddAll(this.productForm, callback);
    },
    /*
       商品点击Tab 
     */
    handleClickMerchantProduct(tab, event) {
      if (tab.label == "生效商品") {
        this.getProductListV2(0, null);
      } else {
        this.getProductListV2(1, null);
      }
    },
    /*
      重置店铺查询 
     */
    resetStoreSearch() {
      this.resetForm("storeSearchForm");
      this.mainStoreTableDataFormFind();
    },
    /*
        店铺查询 
       */
    storeSearch() {
      this.mainStoreTableDataFormFind();
    },

    /*
       重置商家查询 
      */
    resetMerchantSearch() {
      console.log(123);
      this.resetForm("merchantSearchForm");
      this.mainMerchantFormFind();
    },
    /*
    商家查询  
   */
    merchantSearch() {
      this.mainMerchantFormFind();
    },
    /*
     备注无法编辑 
    */
    changeRemark(val) {
      this.$forceUpdate();
    },
    /**
     * 优惠阶梯下标
     */
    indexMethod(index) {
      return (index + 1) * 1;
    },
    /**
     * 格式化活动时间
     */
    SeckillTimeChanage(e) {
      let startTime = formatDate(e[0], "yyyy-MM-dd hh:mm:ss");
      let startTimeArray = startTime.split(" ");
      if (startTimeArray[1] == "00:00:00") {
        startTime =
          startTimeArray[0] +
          " " +
          formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").split(" ")[1];
      }
      let endTime = formatDate(e[1], "yyyy-MM-dd hh:mm:ss");
      let endTimeArray = endTime.split(" ");
      if (endTimeArray[1] == "00:00:00") {
        endTime =
          endTimeArray[0] +
          " " +
          formatDate(new Date(), "yyyy-MM-dd hh:mm:ss").split(" ")[1];
      }
      this.filters.startTime = startTime;
      this.filters.endTime = endTime;
      let startYearDate = startTime.split("-");
      let startTimeDate = startTime.split(":");

      let endYearDate = endTime.split("-");
      let endTimeDate = endTime.split(":");

      this.dataForm.SeckillTime = [
        new Date(
          startYearDate[0],
          startYearDate[1],
          startYearDate[2].split(" ")[0],
          startTimeDate[0].split(" ")[1],
          startTimeDate[1],
          startTimeDate[2]
        ),
        new Date(
          endYearDate[0],
          endYearDate[1],
          endYearDate[2].split(" ")[0],
          endTimeDate[0].split(" ")[1],
          endTimeDate[1],
          endTimeDate[2]
        )
      ];
      console.log(startTime);
    },
    //更换活动描述
    changeDescriptions(val) {
      if (val == 12) {
        this.descriptions = "第X件Y折";
      } else if (val == 13) {
        this.descriptions = "第X件Y元";
      } else {
        this.descriptions = "满X件Y折";
      }
    },
    // 批量删除商品
    batchDelProduct() {
      if (this.repelSelection.length == 0) {
        this.$message({ message: "未选择删除条目", type: "error" });
        return;
      }
      this.$confirm("是否确认删除商品？", "提示", {
        type: "warning"
      })
        .then(() => {
          let this_ = this;
          let callback = function(res) {
            if (res.code == "0000") {
              // 成功查询本地促销商品
              this_.getProductListV2(0, null);
            } else {
              this.$message({ message: "删除商品失败", type: "fail" });
            }
          };
          let ids = this.repelSelection.map(item => item.id).toString();
          let idArray = (ids + "").split(",");
          let param = {};
          param.ids = idArray;
          marketRequest.promotionMerchantProductDeleteBatch(param, callback);
        })
        .catch(() => {});
    },
    // 删除促销商品-单个删除
    delMerchantProducts(id) {
      this.$confirm("是否确认删除商品？", "提示", {
        type: "warning"
      })
        .then(() => {
          let this_ = this;
          let callback = function(res) {
            if (res.code == "0000") {
              // 成功查询本地促销商品
              this_.getProductListV2(0, null);
            } else {
              this_.getProductListV2(0, null);
              alert("删除失败");
            }
          };
          let param = {};
          param.id = id;
          marketRequest.promotionMerchantProductDelete(param, callback);
        })
        .catch(() => {});

      // this.$confirm("确认删除选中记录吗？", "提示", {
      //   type: "warning"
      // })
      //   .then(() => {
      //     console.log(
      //       "=====删除促销商品:promotionId===" + promotionId + "==mpId==" + mpId
      //     );
      //     let this_ = this;
      //     let callback = function(res) {
      //       if (res.code == "0000") {
      //         // 成功查询本地促销商品
      //         console.log(res);
      //         this_.mainProductTableDataFormFind();
      //       } else {
      //         this_.mainProductTableDataFormFind();
      //         this_.$message({ message: "删除失败", type: "error" });
      //       }
      //     };
      //     let param = {};
      //     param.promotionId = promotionId;
      //     param.ids = mpId;
      //     this.utils.request.promotionSingleProductDelete(param, callback);
      //   })
      //   .catch(() => {
      //     // this_.$message({ message: "已取消", type: "warning" });
      //   });
    },
    //产品促销复选框
    handleSelectionChangeProduct(data) {
      this.productChecked = data;
    },
    //批量修改促销商品
    merchantProductEdit() {
      if (this.productChecked.length < 1) {
        this.$message({ message: "批量保存时至少选择一条数据", type: "error" });
        return;
      }
      let this_ = this;
      let params = Object.assign({}, this_.merchantProductEditForm);
      var ids = "";
      for (var i = 0; i < this_.productChecked.length; i++) {
        ids = ids + this_.productChecked[i].mpId + ",";
      }
      params.promotionId = this_.promotionId;
      params.ids = ids;
      this_.utils.request.editSingleMerchantProductEdit(params, function(res) {
        if (res.code == "0000") {
          this_.$message({ message: "操作成功", type: "success" });
          this_.mainProductTableDataFormFind();
        } else if (res.code == "9999") {
          this_.$message({ message: "操作失败", type: "error" });
        }
      });
    },
    //重置商品按钮
    resetMerchantProductSearch() {
      this.resetForm("merchantProductSearchForm");
      this.merchantProductSearch();
    },

    // 保存为模板
    saveTemplate(flag) {
      this.$refs["saveTemplateForm"].validate(valid => {
        if (valid) {
          let callback = res => {
            if (res.code == "0000") {
              this.saveTemplateFlag = 1;
              this.$message({ message: "已保存为模板", type: "success" });
              this.saveTemplateDialog = false;
            } else {
              this.$message({ message: res.msg, type: "fail" });
            }
          };
          this.saveTemplateForm.promotionId = this.promotionId;
          this.utils.request.saveXofferTemplate(
            this.saveTemplateForm,
            callback
          );
        }
      });
    },
    handleCurrentChangeMerchantProduct(pageNum) {
      this.merchantProductSearchForm.start = pageNum;
      this.merchantProductSearch();
      
    },
    handleSizeChangeMerchantProduct(pageSize) {
      this.merchantProductSearchForm.limit = pageSize;
      this.merchantProductSearch()

    },
    /**
     * 渠道选择
     */
    channelCheckChange(data, checked, indeterminate) {
      let index = this.dataForm.channelIds.indexOf(data.id);
      if (index != -1) {
        //存在
        this.dataForm.channelIds.splice(index, 1);
      } else {
        //不存在
        this.dataForm.channelIds.push(data.id);
      }
    },
    /**
     * 标签分类查询
     */
    getTagCategoryList() {
      let that = this;
      this.utils.request.getTagCategoryList({}, res => {
        that.tagCategoryList = res.data.rows;
      });
    },
    /**
     * 新增标签
     */
    addNewTag() {
      this.$refs["addTagForm"].validate(valid => {
        if (valid) {
          // this.addTagForm
          let that = this;
          if (that.addTagForm.tagName.length < 3) {
            that.$message({
              message: "请输入三个以上三十个以下的字符",
              type: "error"
            });
          } else {
            this.utils.request.addTag(this.addTagForm, res => {
              if (res.code == "0000") {
                that.queryTagList(res.data);
                that.addTagDialogFormVisible = false;
                that.$message({
                  message: "添加成功",
                  type: "success"
                });
              } else {
                that.$message({
                  message: "此标签名已被使用,请重新输入",
                  type: "error"
                });
              }
            });
          }
        } else {
          console.log("error submit!!");

          return false;
        }
      });
    },
    /**
     * 新增标签弹窗
     */
    addtags() {
      if (this.$refs["addTagForm"] != undefined) {
        this.$refs["addTagForm"].resetFields();
      }
      this.addTagDialogFormVisible = true;
    },
    merchantProductSearch() {
      this.getProductListV2(0, this.merchantProductSearchForm);
    },

    // setep3--
    removePromotionRuleSet(index, val) {
      this.$confirm("确认删除吗？", "提示", {}).then(() => {
        this.addDis = false;
        this.filters.promotionRules.splice(index, 1);
        if (this.promotionId != null && val.id != "undefined") {
          let callback = function(res) {
            if (res.code == "0000") {
            } else {
              //alert("修改失败");
            }
          };
          let param = {
            id: val.id,
            promotionId: this.promotionId
          };
          this.utils.request.promotionRuleDelete(param, callback);
        }
      });
    },
    addPromotionRuleSet() {
      if (this.filters.promotionRules.length > 3) {
        this.addDis = true;
      }
      this.filters.promotionRules.push({
        level: this.filters.promotionRules.length + 1
      });
    },
    //更新价格或者限量-todo
    updatePriceOrLimit(val) {
      let callback = function(res) {
        if (res.code == "0000") {
          val.limitRuleId = res.data;
        } else {
          //alert("修改失败");
        }
      };
      let temp = {};
      temp.id = val.limitRuleId == 0 ? null : val.limitRuleId;
      temp.promotionId = val.promotionId;
      temp.promotionId = val.promotionId;
      temp.mpId = val.mpId;
      temp.channelStoreLimit = val.channelStoreLimit;
      temp.channelIndividualLimit = val.channelIndividualLimit;
      temp.promPrice = val.promPrice;
      temp.individualLimit = val.individualLimit;
      temp.channelMerchantLimit = val.channelMerchantLimit;
      temp.limitType = val.typeOfProduct == 10 ? 5 : 3; //5spu,3sku
      marketRequest.promotionLimitRuleInsert(temp, callback);
    },

    productTableDataSubmit2() {
      //this.productSaveBatch();
      this.productSaveBatch();
    },
    //确定 选择商品
    productTableData2Click() {
      console.log("======选择商品======" + this.productAddSelection);
      // 调添加商品 接口
      this.productTableDataSubmit2();
    },
    // 选择商品
    addSelectionChangeProduct(val) {
      let this_ = this;
      this_.productAddSelection = val;
      console.log(
        "==========addSelectionChangeProduct选择商品============" +
          JSON.stringify(val)
      );
    },

    //修改table header的背景色
    tableHeaderColor({ row, column, rowIndex, columnIndex }) {
      if (rowIndex === 0) {
        return "background-color:rgb(250,250,250);";
      }
    },
    //table的双色条纹
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return "warning-row";
      } else if (rowIndex === 3) {
        return "success-row";
      }
      return "";
    },
    //添加促销商品
    add() {
      this.dialogVisibleTwo = true;
      this.productFormFind();
    },
    //批量添加商品
    productSaveBatch() {
      this.dialogVisibleTwo = !this.dialogVisibleTwo;
      console.log("productSaveBatch");
      console.log(this.productAddSelection);
      console.log("productSaveBatch2");
      this.productPromotionListObject.productPromotionList.splice(
        0,
        this.productPromotionListObject.productPromotionList.length
      );
      console.log("productSaveBatch promotionList");
      console.log(this.productPromotionListObject.productPromotionList);

      for (let i = 0; i < this.productAddSelection.length; i++) {
        let temp = {};
        temp.promotionId = this.promotionId;
        temp.mpId = this.productAddSelection[i].id;
        temp.mpName = this.productAddSelection[i].chineseName; // 商品名称
        temp.merchantName = this.productAddSelection[i].name; //商家名称
        temp.storeName = this.productAddSelection[i].storeName; //店铺名称
        temp.salePriceWithTax = this.productAddSelection[i].salePriceWithTax; //零售价
        temp.mpCode = this.productAddSelection[i].code; //商品编码
        temp.mpParempParentIdntId = this.productAddSelection[i].parentId;
        temp.merchantId = this.productAddSelection[i].merchantId;
        temp.categoryId = this.productAddSelection[i].categoryId;
        // temp.categoryName     = this.productAddSelection[i].categoryName;    类别名称
        temp.picUrl = this.productAddSelection[i].pictureUrl;
        this.productPromotionListObject.productPromotionList.push(temp);
        console.log(temp);
      }

      let callback = res => {
        if (res.code == "0000") {
          // 查询促销商品
          this.mainProductTableDataFormFind();
        }
      };

      this.utils.request.promotionMerchantProductPromotionalProduct(
        this.productPromotionListObject,
        callback
      );
    },
    //促销商品查询
    getProductListV2(type, searchParm) {
      let this_ = this;
      let callback = function(res) {
        console.log(res);
        if (res.code == "0000") {
          if (type == 0 && res.data.total > 0) {
            this_.merchantProductTableData = res.data.rows;
            this_.merchantProductTableDataTotal = res.data.total;
            this_.alreadyGoodsTotal = res.data.totalCount;
          } else {
            this_.merchantProductTableData = [];
            this_.merchantProductTableDataTotal = 0;
            this_.alreadyGoodsTotal = 0;
          }
        } else {
        }
      };
      this.merchantProductSearchForm.promotionId = this.promotionId;
      marketRequest.getProductListV3(this.merchantProductSearchForm, callback);
    },
    //计算商品总条数
    checkRow(RowData) {
       console.log(RowData,"商品总条数")
      let count = 0;
      RowData.forEach(child => {
        if (child.children) {
          count +=child.children.length;
        }
      });
      return count;
    },
    productTableDataSubmit2() {
      this.batchSaveV2();
    },
    //保存商品具体方法
    batchSaveV2() {
      let this_ = this;
      this.dialogVisibleTwo = !this.dialogVisibleTwo;
      this.productPromotionListObject.productPromotionList.splice(
        0,
        this.productPromotionListObject.productPromotionList.length
      );
      for (let i = 0; i < this.productAddSelection.length; i++) {
        let temp = {};
        temp.promotionId = this.promotionId;
        temp.mpId = this.productAddSelection[i].id;
        temp.spuId = this.productAddSelection[i].id;
        this.productPromotionListObject.productPromotionList.push(temp);
      }
      let callback = res => {
        if (res.code == "0000") {
          // 查询本地促销商品
          this_.getProductListV2(0, null);
        }
      };
      marketRequest.saveBatchV3(this.productPromotionListObject, callback);

      // let this_ = this;
      // this.dialogVisibleTwo = !this.dialogVisibleTwo;
      // this.productPromotionListObject.productPromotionList.splice(0,this.productPromotionListObject.productPromotionList.length);
      // for (let i = 0; i < this.productAddSelection.length; i++) {
      //   let temp = {};
      //   temp.promotionId = this.promotionId;
      //   temp.mpId = this.productAddSelection[i].id;
      //   this.productPromotionListObject.productPromotionList.push(temp);
      // }
      // let callback = res => {
      //   if (res.code == "0000") {
      //     // 查询本地促销商品
      //     this_.getProductListV2(0, null);
      //   }
      // };
      // marketRequest.saveBatchV2(this.productPromotionListObject, callback );
    },
    //确定 选择商品
    productTableData2Click() {
      console.log("======选择商品======" + this.productAddSelection);
      // 调添加商品 接口
      this.productTableDataSubmit2();
    },
    // 选择商品
    addSelectionChangeProduct(val) {
      let this_ = this;
      this_.productAddSelection = val;
      console.log(
        "==========addSelectionChangeProduct选择商品============" +
          JSON.stringify(val)
      );
    },

    // 商品方法开始
    productFormFind() {
      let that_ = this;
      this.productForm.storeIds = this.storeTableData.map((ele, index) => {
           
        return ele.storeId;
      });
      marketRequest.promotionSpuPage(this.productForm, function(resp) {
        if (resp.code == "0000") {
          that_.tableDataTwo = resp.data.rows.map((ele, index) => {
            let spu = {};
            spu.id = ele.id;
            spu.code = ele.id;
            spu.chineseName = ele.goodsName;
            spu.totalStock = ele.stock;
            spu.goodsCategory = ele.goodsCategory;
            spu.merchantName = ele.merchantName;
            spu.storeName = ele.storeName;
            spu.salePriceScope = ele.salePriceScope;
            spu.thirdSpuId = ele.thirdSpuId;
            return spu;
          });
          that_.productListTotal = resp.data.total;
        }
      });
      // let that_ =this;
      // that_.utils.request.queryshopApi(this.productForm, function (resp) {
      //   if (resp.code == "0000") {
      //     that_.tableDataTwo= resp.data.rows;
      //     that_.productListTotal= resp.data.total;
      //   }
      //
      //   that_.tableDataTwo= resp.data.rows;
      // });
    },
    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },
    // setep3--end

    checkPromotin(flag) {
      if (flag == 0) {
        this.$confirm("是否确认提交审核？", "提示", {
          type: "warning"
        })
          .then(() => {
            this.shenhe = 1;

            let callback = res => {
              console.log(res);
            };
            let param = {};
            param.id = this.promotionId;
            param.status = 2;
            this.utils.request.promotionUpdate(param, callback);
          })
          .catch(() => {});
      } else {
        this.shenhe = 2;
        this.dialogVisibleAdmin = true;
      }
    },
    detailList() {
      this.$router.push({
        path: `/pages/promotionManagement/XofferPromotion`
      });
    },
    submitFormAdminNotPass() {
      this.dialogVisibleAdmin = false;

      let callback = res => {
        console.log(res);
      };
      this.adminDataForm.id = this.promotionId;
      this.adminDataForm.status = 4;
      this.utils.request.promotionUpdate(this.adminDataForm, callback);
    },
    submitFormAdmin() {
      this.dialogVisibleAdmin = false;

      let callback = res => {
        console.log(res);
      };
      this.adminDataForm.id = this.promotionId;
      this.adminDataForm.status = 11;
      this.utils.request.promotionUpdate(this.adminDataForm, callback);
    },

    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].resetFields();
      }
    },
    //---------------------------店铺------------------------------------------------start
    //查询店铺
    storeFormFind() {
      //商家 取出商家id-->merchantId
      // this.merchantTableData2;

      let ids = this.merchantTableData2.map(item => item.merchantId).toString();

      console.log("----ids");
      console.log(this.merchantTableData2);
      console.log(ids);
      console.log("----ids---2");

      let params = [];
      console.log("----idArray---");
      let idArray = (ids + "").split(",");
      console.log(idArray);
      console.log("----idArray---2");

      for (var i = 0; i < idArray.length; i++) {
        params.push({ id: idArray[i] });
      }

      console.log("----params");
      console.log(params);
      console.log("----params--2");

      console.log(this.merchantTableData.length);
      console.log("----");
      console.log(this.merchantTableData);

      // mergeTo = mergeTo.concat(mergeFrom);

      if (this.merchantTableData2.length == 0) {
        this.$message({ message: "请先选择商家", type: "error" });
      }

      // this.merchantTableDataTatol;
      this.storeTableData2.splice(0, this.storeTableData2.length);
      var this__ = this;
      this.storeForm.merchantIds = ids;
      this.utils.request.queryByIds(this.storeForm, function(res) {
        console.log(res);
        if (res.code == "0000") {
          // this__.storeTableData2= this__.storeTableData2.concat(res.data);
          this__.storeTableData2 = res.data.rows;
          this__.merchantTableDataTatolStore = res.data.total;
        }
      });
    },
    storeTableDataselectionChange(val) {
      this.storeTableDataSelection = val;
    },
    merchantTableData2selectionChange(val) {
      this.merchantTableData2Selection = val;
    },
    //选择店铺
    storeTableData2AddSelectionChange(val) {
      this.addSelectionStoreTableData2 = val;
    },
    //确定 选择店铺
    storeTableData2Click() {
      console.log(this.addSelectionStoreTableData2);
      // 调添加店铺 关系接口
      this.merchantTableDataSubmit2();
    },
    merchantTableDataSubmit2() {
      // this.merchantTableData2 = this.addSelection;
      this.storeSaveBatch();
      // let callback = res => {
      //   console.log(res);
      //   if (res.code == "0000") {
      //     this.storeSaveBatch();
      //   }
      // };

      // //调接口
      // //删除这个活动老的数据
      // //批量添加新的数据
      // this.promotion.id = null;
      // this.promotion.promotionId = this.promotionId;
      // this.promotion.merchantType = "2";
      // this.utils.request.promotionMerchantDeleteByPromotionId(
      //   this.promotion,
      //   callback
      // );
    },

    //批量添加店铺
    storeSaveBatch() {
      console.log("storeSaveBatch");
      console.log(this.addSelectionStoreTableData2);
      console.log("storeSaveBatch2");
      this.pomotionListObject.pomotionList.splice(
        0,
        this.pomotionListObject.pomotionList.length
      );
      console.log("storeSaveBatch pomotionList");
      console.log(this.pomotionListObject.pomotionList);
      console.log("storeSaveBatch pomotionList2");

      for (var i = 0; i < this.addSelectionStoreTableData2.length; i++) {
        var temp = {};

        temp.promotionId = this.promotionId;
        temp.storeId = this.addSelectionStoreTableData2[i].id;
        temp.merchantType = "2";
        temp.storeName = this.addSelectionStoreTableData2[i].storeName;
        temp.merchantId = this.addSelectionStoreTableData2[i].merchantId;
        temp.storeCode = this.addSelectionStoreTableData2[i].storeCode;
        temp.storeType = this.addSelectionStoreTableData2[i].storeType;

        this.pomotionListObject.pomotionList.push(temp);
      }
      console.log("storeSaveBatch promotionMerchantSaveBatch push ok");
      console.log(this.pomotionListObject.pomotionList);
      console.log("storeSaveBatch promotionMerchantSaveBatch push ok2");

      let callback = res => {
        console.log(res);
        if (res.code == "0000") {
          this.mainStoreTableDataFormFind();
        }
      };

      this.utils.request.promotionMerchantSaveBatch(
        this.pomotionListObject,
        callback
      );
    },
    //查询绑定关系的店铺
    mainStoreTableDataFormFind() {
      // this.storeTableData
      this.storeSearchForm.merchantType = "2";
      this.storeSearchForm.promotionId = this.promotionId;
      var this__ = this;
      this.utils.request.promotionMerchantList(this.storeSearchForm, function(
        res
      ) {
        if (res.code == "0000") {
          var ret = [];
          for (var i = 0; i < res.data.list.length; i++) {
            var temp = {};
            temp.promotionId = res.data.list[i].promotionId;
            temp.id = res.data.list[i].id;
            temp.storeId = res.data.list[i].storeId;
            temp.storeName = res.data.list[i].storename;
            temp.storeCode = res.data.list[i].storecode;
            temp.storeType = res.data.list[i].storeType;

            ret.push(temp);
          }
          //店铺调试
          this__.storeTableData = res.data.list;
          this__.storeTableDataTatol = res.data.totalCount;
        }
      });
    },

    // 店铺换页刷新
    mainSroreMerchantRefreshPageRequest: function(pageNum) {
      console.log(pageNum,"*-*-*-*-*")
      this.storeSearchForm.pageNo = pageNum;
      this.mainStoreTableDataFormFind();
    },
    // 店铺换页刷新
    mainSroreMerchantHandleSizeChange: function(pageSize) {
      console.log(pageSize,"+*+*+**+*")
      this.storeSearchForm.pageNo = 1;
      this.storeSearchForm.pageSize = pageSize;
      this.mainStoreTableDataFormFind();
    },

    // 换页刷新
    refreshPageRequestStore: function(pageNum) {
      console.log(pagNum,"----***+++------")
      this.merchantFormStore.start = pageNum;
      // this.merchantFormFind();
      this.storeFormFind();
    },
    // 换页刷新
    handleSizeChangeStore: function(pageSize) {
       console.log(pageSize,"----**+++-----")
      this.merchantFormStore.limit = pageSize;
      this.merchantFormStore.start = 1;
      this.storeFormFind();
    },

    //---------------------------店铺------------------------------------------------end

    //---------------------------商家------------------------------------------------start

    //---------------------------分页------------------------------------------------start
    // 换页刷新
    refreshPageRequest: function(pageNum) {
      this.merchantForm.start = pageNum;
      this.merchantFormFind();
    },
    // 换页刷新
    handleSizeChange: function(pageSize) {
      this.merchantForm.limit = pageSize;
      this.merchantForm.start = 1;
      this.merchantFormFind();
    },
    producthandleCurrentChange(pageNum) {
      this.productForm.start = pageNum;
      this.productFormFind();
    },
    // 换页刷新
    mainMerchantRefreshPageRequest: function(pageNum) {
      console.log(pageNum, "*-*-*-*---");
      this.merchantSearchForm.pageNo = pageNum;
      this.mainMerchantFormFind();
    },
    producthandleSizeChange(pageSize) {
      this.productForm.start = 1;
      this.productForm.limit = pageSize;
      this.productFormFind();
    },
    // 换页刷新
    mainMerchantHandleSizeChange: function(pageSize) {
      console.log(pageSize, "***********");
      this.merchantSearchForm.pageNo = 1;
      this.merchantSearchForm.pageSize = pageSize;
      this.mainMerchantFormFind();
    },
    //查询绑定关系的商家
    mainMerchantFormFind() {
      this.merchantSearchForm.merchantType = "1";
      var this__ = this;
      this.merchantSearchForm.promotionId = this.promotionId;
      this.utils.request.promotionMerchantList(
        this.merchantSearchForm,
        function(res) {
          console.log(res);
          if (res.code == "0000") {
            var ret = [];
            for (var i = 0; i < res.data.list.length; i++) {
              var temp = {};
              temp.id = res.data.list[i].id;
              temp.name = res.data.list[i].merchantName;
              temp.orgNumber = res.data.list[i].orgNumber;
              temp.merchantType = res.data.list[i].merchantTypeManager;
              temp.merchantId = res.data.list[i].merchantId;

              ret.push(temp);
            }

            this__.merchantTableData2 = ret;
            this__.mainMerchantTableDataTatol = res.data.totalCount;
          }
        }
      );
    },
    // 删除店铺
    storeDelete(id) {
      this.$confirm("确认删除吗？", "提示", {}).then(() => {
        let callback = res => {
          console.log(res);
          this.mainStoreTableDataFormFind();

          if (res.code == "0000" && res.data == "1") {
            //删除成功再调分页
            this.$message({ message: "删除成功", type: "success" });
          } else {
            this.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        };

        this.promotion.id = id;
        this.utils.request.promotionMerchantDeleteById(
          this.promotion,
          callback
        );
      });
    },

    //---------------------------分页------------------------------------------------end
    //删除商家
    merchantTableData2delete(id) {
      this.$confirm("确认删除吗？", "提示", {}).then(() => {
        let callback = res => {
          console.log(res);
          this.mainMerchantFormFind();
          this.mainStoreTableDataFormFind();
          if (res.code == "0000" && res.data == "1") {
            //删除成功再调分页
            this.$message({ message: "删除成功", type: "success" });
          } else {
            this.$message({ message: "操作失败, " + res.msg, type: "error" });
          }
        };

        this.promotion.id = id;
        this.utils.request.promotionMerchantDeleteById(
          this.promotion,
          callback
        );
      });
    },

    //选择商家
    addSelectionChange(val) {
      this.addSelection = val;
      console.log(this.addSelection);
    },
    //提交 选择商家
    merchantTableDataSubmit() {
      // this.merchantTableData2 = this.addSelection;
      this.promotionMerchantSaveBatch();
      // let callback = res => {
      //   console.log(res);
      //   if (res.code == "0000") {
      //     this.promotionMerchantSaveBatch();
      //   }
      // };

      // //调接口
      // //删除这个活动老的数据
      // //批量添加新的数据
      // this.promotion.id = null;
      // this.promotion.promotionId = this.promotionId;
      // this.promotion.merchantType = "1";
      // this.utils.request.promotionMerchantDeleteByPromotionId(
      //   this.promotion,
      //   callback
      // );
    },
    promotionMerchantSaveBatch() {
      console.log("promotionMerchantSaveBatch");
      console.log(this.addSelection);
      console.log("promotionMerchantSaveBatch2");
      this.pomotionListObject.pomotionList.splice(
        0,
        this.pomotionListObject.pomotionList.length
      );
      console.log("pomotionList");
      console.log(this.pomotionListObject.pomotionList);
      console.log("pomotionList2");

      for (var i = 0; i < this.addSelection.length; i++) {
        var temp = {};

        temp.promotionId = this.promotionId;
        temp.merchantId = this.addSelection[i].id;
        temp.merchantType = "1";
        temp.merchantName = this.addSelection[i].name;
        temp.merchantTypeManager = this.addSelection[i].merchantType;
        temp.orgNumber = this.addSelection[i].orgNumber;
        temp.name = this.addSelection[i].name;

        this.pomotionListObject.pomotionList.push(temp);
      }
      console.log("promotionMerchantSaveBatch push ok");
      console.log(this.pomotionListObject.pomotionList);
      console.log("promotionMerchantSaveBatch push ok2");

      let callback = res => {
        console.log(res);
        if (res.code == "0000") {
          this.mainMerchantForm.merchantType = "1";
          this.mainMerchantFormFind();
        }
      };

      var this__ = this;
      this.utils.request.promotionMerchantSaveBatch(
        this.pomotionListObject,
        callback
      );

      console.log("----ok");
      console.log(this.merchantTableData2);
      console.log("----ok2");
    },
    //查询商家
    merchantFormFind() {
      var this__ = this;
       
      this.utils.request.queryMerchantList(this.merchantForm, function(res) {
        // this.utils.request.queryMerchantListOther(null, function (res) {
        if (res.code == "0000") {
          this__.merchantTableData = res.data.rows;
          this__.merchantTableDataTatol = res.data.total;
        }
      });
    },
    //重置商家弹窗
    resetMerForm() {
      var this__ = this;
       this__.merchantForm = {}
       this__.merchantForm.start = 1
       this__.merchantForm.limit =10
      this__.merchantForm.childIds = this.$refs.channelTree.getCheckedKeys();
       this.promotion.merchantType = 1;
      this.utils.request.queryMerchantList(  this__.merchantForm, function(res) {
        // this.utils.request.queryMerchantListOther(null, function (res) {
        if (res.code == "0000") {
          this__.merchantTableData = res.data.rows;
          this__.merchantTableDataTatol = res.data.total;
        }
      });
    },
    //---------------------------商家------------------------------------------------end

    handleCheckedCitiesChange(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.chanelCodesRadios.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.chanelCodesRadios.length;
    },

    handleCheckedCitiesChange1(value) {
      let checkedCount = value.length;
      this.checkAll1 = checkedCount === this.proPlatformRadios.length;
      this.isIndeterminate1 =
        checkedCount > 0 && checkedCount < this.proPlatformRadios.length;
    },
    //新老用户
    handleCheckAllChange2(val) {
      this.filters.proUserType = val
        ? proUserTypeRadio.map(function(value, index, array) {
            return value.code;
          })
        : [];
      this.isIndeterminate2 = false;
    },
    handleCheckedCitiesChange2(value) {
      let checkedCount = value.length;
      this.checkAll2 = checkedCount === this.proUserTypeRadios.length;
      this.isIndeterminate2 =
        checkedCount > 0 && checkedCount < this.proUserTypeRadios.length;
    },

    handleCheckedCitiesChange3(value) {
      let checkedCount = value.length;
      this.checkAll3 = checkedCount === this.proMemberTypeRadios.length;
      this.isIndeterminate3 =
        checkedCount > 0 && checkedCount < this.proMemberTypeRadios.length;
    },

    handleCheckedCitiesChange4(value) {
      let checkedCount = value.length;
      this.checkAll4 = checkedCount === this.proMemberLevelRadios.length;
      this.isIndeterminate4 =
        checkedCount > 0 && checkedCount < this.proMemberLevelRadios.length;
    },
    //添加商家
    querySupplierListForAdd() {
     this.merchantForm.childIds = this.$refs.channelTree.getCheckedKeys();
      this.editDialogVisible = true;
      this.promotion.merchantType = 1;
      this.merchantFormFind();
    },
    //添加店铺
    querySupplierListForAdd2() {
      this.editDialogVisible2 = true;
      this.promotion.merchantType = 2;
      this.storeFormFind();
    },
    delAllSelectedSupplierstoreTableData() {
      if (this.storeTableDataSelection.length == 0) {
        this.$message({ message: "未选择删除条目", type: "error" });
        return;
      }
      this.$confirm("确认删除选中记录吗？", "提示", {
        type: "warning"
      })
        .then(() => {
          let ids = this.storeTableDataSelection
            .map(item => item.id)
            .toString();
          let idArray = (ids + "").split(",");
          this.delAllSelectedSupplierstoreTableDataQueryList(idArray);
        })
        .catch(() => {});
    },
    delAllSelectedSupplierstoreTableDataQueryList(idArray) {
      let that = this;
      this.promotion.merchantType = "2";
      this.promotion.id = idArray[this.storeTableDataSelectionIndex];
      this.utils.request.promotionMerchantDeleteById(
        this.promotion,
        function() {
          that.storeTableDataSelectionIndex++;
          if (that.storeTableDataSelectionIndex < idArray.length) {
            that.delAllSelectedSupplierstoreTableDataQueryList(idArray);
          } else {
            //执行成功
            that.storeTableDataSelectionIndex = 0;
            that.$message({ message: "删除成功", type: "success" });
            that.mainStoreTableDataFormFind();
          }
        }
      );
    },
    //批量删除商家
    delAllSelectedSuppliermerchantTableData2() {
      if (this.merchantTableData2Selection.length == 0) {
        this.$message({ message: "未选择删除条目", type: "error" });
        return;
      }
      this.$confirm("确认删除选中记录吗？", "提示", {
        type: "warning"
      })
        .then(() => {
          // this.merchantTableData2Selection;
          let ids = this.merchantTableData2Selection
            .map(item => item.id)
            .toString();
          let idArray = (ids + "").split(",");
          this.delAllSelectedSupplierQueryList(idArray);
        })
        .catch(() => {});
    },
    delAllSelectedSupplierQueryList(idArray) {
      let that = this;
      this.promotion.merchantType = "1";
      this.promotion.id = idArray[this.merchantTableData2SelectionIndex];
      this.utils.request.promotionMerchantDeleteById(
        this.promotion,
        function() {
          that.merchantTableData2SelectionIndex++;
          if (that.merchantTableData2SelectionIndex < idArray.length) {
            that.delAllSelectedSupplierQueryList(idArray);
          } else {
            //执行成功
            that.merchantTableData2SelectionIndex = 0;
            that.$message({ message: "删除成功", type: "success" });
            that.mainMerchantFormFind();
            that.mainStoreTableDataFormFind();
            that.getProductListV2(0,null);
          }
        }
      );
    },

    // ------------------------------------商品开始方法-------------------------------------start

    // 换条数刷新
    handleSizeChangeForProduct: function(pageSize) {
      this.productForm.limit = pageSize;
      this.productForm.start = 1;
      this.productFormFind();
    },

    // 换页刷新
    handleCurrentChangeForProduct: function(pageNum) {
      this.productForm.start = pageNum;
      this.productFormFind();
    },

    // 商品多项目选择
    productSelectionChange(val) {
      console.log("================================" + val);
      // this.storeTableDataSelection=val;
    },

    // 选择商品
    addSelectionChangeProduct(val) {
      let this_ = this;
      this_.productAddSelection = val;
      console.log("==========选择商品============" + JSON.stringify(val));
    },

    //查询促销商品
    mainProductTableDataFormFind() {
      this.mainProductForm.promotionId = this.promotionId;
      let this_ = this;
      this.utils.request.promotionMerchantProductList(
        this.mainProductForm,
        function(res) {
          console.log(res);
          if (res.code == "0000") {
            // let ret = [];
            // for (let i = 0; i < res.data.list.length; i++) {
            //   var temp = {};
            //   temp.mpCode          = res.data.list[i].mpCode;
            //   temp.productName                   = res.data.list[i].mpName;
            //   temp.barcode              = res.data.list[i].barcode;
            //   // temp.unit            = res.data.list[i].unit;
            //   temp.merchantName            = res.data.list[i].merchantName;
            //   ret.push(temp);
            // }
            //
            this_.merchantProductTableData = res.data.rows;
            this_.merchantProductTableDataTotal = res.data.total;
          }
        }
      );
    },

    //获取活动列表
    getTagList() {
      let this_ = this;
      this.tagList = [
        { id: 1, tagName: "标签1" },
        { id: 2, tagName: "标签2" },
        { id: 3, tagName: "标签3" }
      ];
      let callback = res => {
        if (res.code == "0000") {
          this_.tagList = res.data.rows;
        }
      };
      this.utils.request.getTagList({ start: 1, limit: 1000 }, callback);
    },
    // ------------------------------------商品结束方法-------------------------------------end
    //增加活动步骤
    addActive() {
      if (this.active++ > 3) {
        this.$router.push({
          path: "/pages/promotionManagement/XofferPromotion"
        });
      }

      //第二步查询方法
      if (this.active == 2) {
        this.getProductListV2(0, null);
      }
    },
    //回退
    back() {
      this.active = this.active - 1;
    },
    //下一步
    next() {
      let _this = this;
      let callback = function(res) {
        if (res.code == "0000") {
          _this.promotionId = res.data;
          _this.filters.id = res.data;
          _this.promotion.promotionId = res.data;
          _this.mainMerchantForm.promotionId = res.data;
          _this.mainStoreMerchantForm.promotionId = res.data;
          _this.addActive();
          _this.mainMerchantFormFind();
          _this.mainStoreTableDataFormFind();
        } else {
          _this.$message({
            message: "操作失败，请重试",
            type: "fail"
          });
          _this.active = 1;
        }
      };
      let callbackUpdate = function(res) {
        if (res.code == "0000") {
          _this.addActive();
          _this.mainMerchantFormFind();
          _this.mainStoreTableDataFormFind();
        } else {
          _this.$message({ message: "操作失败", type: "fail" });
          _this.active = 1;
        }
      };
      //保存活动基础配置
      if (this.active == 1) {
        this.$refs["filters"].validate(valid => {
          let this_ = this;
          this_.filters;
          if (valid) {
            if (this_.promotionId == null) {
              this_.filters.status = 0;
              //当前登录用户身份为母平台校验所属渠道
              if (this.deptType == 0) {
                if (this.$refs.channelTree.getCheckedKeys().length <= 0) {
                  this.$message({ message: "请选择使用渠道" });
                  loading.close();
                  return false;
                } else {
                  this.filters.channelCodes = this.$refs.channelTree
                    .getCheckedKeys()
                    .join(",");
                }
              }
              this_.utils.request.promotionCreate(this_.filters, callback);
            } else {
              //当前登录用户身份为母平台校验所属渠道
              if (this.deptType == 0) {
                if (this.$refs.channelTree.getCheckedKeys().length <= 0) {
                  this.$message({ message: "请选择使用渠道" });
                  loading.close();
                  return false;
                } else {
                  this.filters.channelCodes = this.$refs.channelTree
                    .getCheckedKeys()
                    .join(",");
                }
              }
              this_.utils.request.promotionUpdate(
                this_.filters,
                callbackUpdate
              );
            }
          }
        });
      }
      //更新活动状态
      if (this.active == 3 || this.active == 4) {
        if (this.active == 3 && this.merchantProductTableData.length == 0) {
          _this.$message({ message: "商品未添加", type: "fail" });
          return;
        }
        let callback = function(res) {
          if (res.code == "0000") {
            _this.addActive();
          } else {
            console.log("修改失败");
            _this.addActive();
          }
        };
        let params = {
          id: this.promotionId,
          status: this.active == 3 ? 1 : 3
        };
        this.utils.request.promotionUpdateStatus(params, callback);
      }
      if (this.active == 2) {
        if (
          this.storeTableData.length == 0 ||
          this.merchantTableData2.length == 0
        ) {
          //判断商家店铺
          _this.$message({ message: "商家或店铺未添加", type: "fail" });
          return;
        }
        this.getProductListV2(0,null);
        this.addActive();
      }
      if (this.active == 4) {
        this.$message({ message: "操作成功", type: "success" });
        return;
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    //批量选择删除商品
    handleBatchDeleteSelection(val) {
      this.batchDeleteSelection = val.map(item => {
        return item.id;
      });
    },
    //批量删除商品-todo
    delBatchMerchantProducts(ids) {
      let callback = function(res) {
        if (res.code == "0000") {
          this.getProductListV2(0,null);
        } else {
          alert("删除失败");
        }
      };
      let param = { ids: ids };
      this.utils.request.promotionMerchantProductDeleteBatch(param, callback);
    },

    repelSelectionChange(val) {
      this.repelSelection = val;
    },
    createPage() {
      this.$router.push("/CreatePromotion");
    },
    handleClick(tab, event) {
      console.log(tab, event);
      if (tab.name == "0") {
        // 触发‘配置管理’事件
        this.first();
      } else {
        // 触发‘用户管理’事件
        this.second();
      }
    },
    first() {
      console.log("生效商品");
      this.modalShow = 1;
    },
    //添加商品弹窗
    productSelectionModal() {
      this.productVisible = true;
    },
    showBatchSetUp() {
      if (this.search == true) {
        this.search = false;
      }
      if (this.setUp == false) {
        this.setUp = true;
      } else if (this.setUp == true) {
        this.setUp = false;
      }
    },
    showQueryCondition() {
      if (this.setUp == true) {
        this.setUp = false;
      }
      if (this.search == false) {
        this.search = true;
      } else if (this.search == true) {
        this.search = false;
      }
    },
    batchReAdd() {
      if (this.multipleSelection.length < 1) {
        this.$message({ message: "请选择要设置的商品", type: "error" });
        return false;
      }
      this.$message({ message: "操作成功", type: "success" });
    },
    updatePriceAndLimit(val) {},
    importCommodityModal(val) {
      if (val === 1) {
        this.operation = true;
      } else if (val == 2) {
        this.operation = false;
      }
      this.uploadVisible = true;
    },
    // 取值
    getValue(value) {
      this.valueId = value;
      console.log(this.valueId);
    },
    handleCheckChange(data, checked, indeterminate) {
      console.log(data, checked, indeterminate);
      console.log(this.$refs.selectTree);
    },
    handleClose() {
      console.log("关闭审核弹窗");
    },
    /**
     * 查询标签List
     */
    queryTagList(id) {
      let that = this;
      that.utils.request.getTagList({}, res => {
        this.tagList = res.data.rows;
        if (id != null) {
          that.filters.labelId = id;
        }
      });
    },
    /*
     * 正整数校验
     */
    positiveInteger(val) {
      if (val != "") {
        const r = /^\+?[1-9][0-9]*$/; // 正整数
        // 如果判断不符合正则，则不是正整数不能提交
        if (!r.test(val)) {
          this.$message({ message: "此处必须为正整数", type: "error" });
        }
      }
    },

    /*
     *保存为模板弹窗 */
    showSaveTemplate() {
      this.saveTemplateDialog = true;
    },
    /*
     *下载模板*/
    // 模板下载
    downloadTemplate() {
      window.location.href =
        this.utils.getHost() + "jic-market/resource/download?key=PRESELL";
    },
    //获取子平台列表
    getChildList() {
      let this_ = this;
      let channel = { childName: "卡奥斯运营平台", id: "179" };
      this_.utils.request.queryChildList({}, res => {
        if (res.code == "0000" && res.data && res.data.length > 0) {
          channel.children = res.data;
          this_.channelList.push(channel);
          if (this_.promotionId == null) {
            this_.$nextTick(() => {
              res.data.forEach(item => {
                this_.$refs.channelTree.setChecked(item.id, true, false);
              });
            });
          }
        }
      });
      console.log(this_.channelList);
    },
    //店铺新增弹窗重置
    restStoreForm() {
      this.storeForm = {};
      let ids = this.merchantTableData2.map(item => item.merchantId).toString();

      console.log("----ids");
      console.log(this.merchantTableData2);
      console.log(ids);
      console.log("----ids---2");

      let params = [];
      console.log("----idArray---");
      let idArray = (ids + "").split(",");
      console.log(idArray);
      console.log("----idArray---2");

      for (var i = 0; i < idArray.length; i++) {
        params.push({ id: idArray[i] });
      }
      // this.merchantTableDataTatol;
      this.storeTableData2.splice(0, this.storeTableData2.length);
      var this__ = this;
      let storeParams = {};
      storeParams.merchantIds = ids;
      storeParams.start = 1;
      storeParams.limit = 10;
      this.utils.request.queryByIds(storeParams, function(res) {
        console.log(res);
        if (res.code == "0000") {
          // this__.storeTableData2= this__.storeTableData2.concat(res.data);
          this__.storeTableData2 = res.data.rows;
          this__.merchantTableDataTatolStore = res.data.total;
        }
      });
    }
  },
  computed: {
    /* 转树形数据 */
    optionData() {
      let cloneData = JSON.parse(JSON.stringify(this.list)); // 对源数据深度克隆
      return cloneData.filter(father => {
        // 循环所有项，并添加children属性
        let branchArr = cloneData.filter(child => father.id == child.parentId); // 返回每一项的子级数组
        branchArr.length > 0 ? (father.children = branchArr) : ""; //给父级添加一个children属性，并赋值
        return father.parentId == 0; //返回第一层
      });
    }
  },
  mounted() {
    //活动id
    //0-创建-1-编辑；
    this.auth = this.$route.query.auth;
    this.getTagCategoryList();
    this.queryTagList();
  }
};
</script>

<style scoped>
.pdL10 {
  padding-left: 10px !important;
}
.mgB15 {
  margin-bottom: 15px !important;
}
.border-left {
  border-left: 3px #ddd solid !important;
}
.font-bold {
  font-weight: 700;
}
.form-group {
  margin-bottom: 15px !important;
  margin-right: -0px !important;
  margin-left: -0px !important;
}
.form-horizontal .control-label {
  padding-top: 5px;
  margin-bottom: 0;
  text-align: right;
}
.form-horizontal div {
  font-family: "Source Sans Pro", "Helvetica Neue", Helvetica, Arial, sans-serif,
    "Regular", "Microsoft YaHei";
  font-size: 12px;
  color: #666666;
  background-color: transparent;
  -webkit-font-smoothing: antialiased;
  line-height: 1.42857143;
  word-wrap: break-word;
}
.form-horizontal .control-label {
  padding-top: 3px !important;
}
.col-sm-2 {
  width: 16.66666667%;
}
/* .col-sm-10 {
      width: 83.33333333%;
  } */
.col-sm-1,
.col-sm-2,
.col-sm-3,
.col-sm-4,
.col-sm-5,
.col-sm-6,
.col-sm-7,
.col-sm-8,
.col-sm-9,
.col-sm-10,
.col-sm-11,
.col-sm-12 {
  float: left;
}
.col-xs-1,
.col-sm-1,
.col-md-1,
.col-lg-1,
.col-xs-2,
.col-sm-2,
.col-md-2,
.col-lg-2,
.col-xs-3,
.col-sm-3,
.col-md-3,
.col-lg-3,
.col-xs-4,
.col-sm-4,
.col-md-4,
.col-lg-4,
.col-xs-5,
.col-sm-5,
.col-md-5,
.col-lg-5,
.col-xs-6,
.col-sm-6,
.col-md-6,
.col-lg-6,
.col-xs-7,
.col-sm-7,
.col-md-7,
.col-lg-7,
.col-xs-8,
.col-sm-8,
.col-md-8,
.col-lg-8,
.col-xs-9,
.col-sm-9,
.col-md-9,
.col-lg-9,
.col-xs-10,
.col-sm-10,
.col-md-10,
.col-lg-10,
.col-xs-11,
.col-sm-11,
.col-md-11,
.col-lg-11,
.col-xs-12,
.col-sm-12,
.col-md-12,
.col-lg-12 {
  /* position: relative; */
  min-height: 1px;
  padding-right: 15px;
  padding-left: 15px;
}
label {
  font-weight: normal;
}
label {
  display: inline-block;
  max-width: 100%;
  margin-bottom: 5px;
  font-weight: bold;
}
.form-group .pdt3px {
  padding-top: 3px;
}
.b-b {
  border-bottom: 1px solid #dddddd;
}
.line-dashed {
  border-style: dashed !important;
  background-color: transparent;
  border-width: 0;
}
.line-lg {
  margin-top: 15px;
  margin-bottom: 15px;
}
.line {
  width: 100%;
  height: 2px;
  margin: 10px 0;
  font-size: 0;
  overflow: hidden;
}
table {
  background-color: transparent;
}
table {
  border-spacing: 0;
  border-collapse: collapse;
}
.i-checks {
  padding-left: 0;
  margin-right: 15px;
  cursor: pointer;
  color: #666666;
}
.radio-inline,
.checkbox-inline {
  display: inline-block;
  padding-left: 20px;
  margin-bottom: 0;
  font-weight: normal;
  vertical-align: middle;
  cursor: pointer;
}
.panel-body tr {
  padding: 0 15px;
}
.mgt15 {
  margin-top: 15px;
}
.type {
  display: flex;
  align-items: center;
}
.type p {
  text-align: right;
  margin-right: 20px;
  width: 120px;
}
/deep/ button {
  margin-bottom: 10px;
  margin-left: 10px;
}

/deep/ .content {
  padding: 10px;
  font-size: 14px;
  color: #666666;
  background-color: #fff;
  padding-bottom: 100px;
}
.title {
  font-weight: 700;
  border-left: 4px solid #ddd;
  padding-left: 10px;
}
.item {
  padding-left: 10%;
  /* width: 100%; */
}
.input {
  height: 28px !important;
  line-height: 28px !important;
  -webkit-appearance: none;
  background-color: #fff;
  background-image: none;
  border-radius: 4px;
  border: 1px solid #dcdfe6;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  color: #606266;
  display: inline-block;
  font-size: inherit;
  height: 40px;
  line-height: 40px;
  outline: 0;
  padding: 0 15px;
  font: 400 13.3333px Arial;
  -webkit-transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
  width: 30%;
}
.bottom-btn {
  position: fixed;
  bottom: 0px;
  width: 100%;
  height: 30px;
  line-height: 30px;
  padding-left: 40%;
  background-color: #fff;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding-bottom: 30px;
  padding-top: 30px;
  z-index: 4;
}
.pointer-input /deep/ input {
  cursor: pointer;
}
.youhuiquan {
  background: url(/static/4.png) center top no-repeat;
  margin-left: auto;
  height: 200px;
  position: absolute;
  right: 10%;
  top: 58%;
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
  color: #c8cbd0;
  /* font-size: 16px; */
}

input:-moz-placeholder,
textarea:-moz-placeholder {
  color: #c8cbd0;
  /* font-size: 16px; */
}

input::-moz-placeholder,
textarea::-moz-placeholder {
  color: #c8cbd0;
  /* font-size: 16px; */
}

input:-ms-input-placeholder,
textarea:-ms-input-placeholder {
  color: #c8cbd0;
  /* font-size: 16px; */
}
/**
      图片列表css
  */
.img-card {
  width: 140px;
  height: 140px;
  line-height: 140px;
  margin-left: 10px;
  margin-top: 10px;
  position: relative;
  cursor: pointer;
}
.img-card-upload {
  width: 140px;
  height: 140px;
  line-height: 130px;
  margin-left: 10px;
  margin-top: 10px;
  margin-bottom: 10px;
}
/**
     修改element上传组件样式
  */
.el-upload-dragger-update {
  text-align: center;
  margin-left: -10px;
  margin-bottom: 20px;
}
.el-upload-dragger-update /deep/ .el-upload .el-upload-dragger {
  border: 0px;
  /* width: 100px; */
  height: 42px;
}

/*素材弹窗 */

/deep/ .el-main {
  padding: 0;
  padding-left: 20px;
}
.el-aside-Superior /deep/ .el-tabs {
  height: 600px;
}
.material-main {
  width: 99%;
  height: 600px;
  background: #fff;
  border: 1px solid #dcdfe6;
  -webkit-box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12),
    0 0 6px 0 rgba(0, 0, 0, 0.04);
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.12), 0 0 6px 0 rgba(0, 0, 0, 0.04);
  position: relative;
}
.material-header {
  display: flex;
  justify-content: space-between;
}
.material-title-right {
  margin-top: 20px;
  margin-right: 30px;
}
.material-title-left {
  margin-top: 20px;
  margin-left: 30px;
  font-size: 15px;
  color: #2F4554;
}
.material-main-list {
  display: flex;
  flex-wrap: wrap;
  margin-top: 20px;
}
.material-main-item {
  margin-left: 10px;
  width: 145px;
  height: 210px;
  padding: 5px;
  margin-bottom: 5px;
  border: 1px solid #fff;
  cursor: pointer;
}
.material-main-item-img {
  width: 100%;
  height: 180px;
}
.material-main-item-name {
  margin-top: 5px;
  color: #909399;
}
.material-main-item-select {
  border: 1px solid #2F4554;
}
.el-upload-list-item-actions {
  position: absolute;
  width: 100%;
  height: 100%;
  left: 0;
  top: 0;
  cursor: default;
  text-align: center;
  color: #fff;
  /* opacity: 0; */
  display: none;
  font-size: 20px;
  background-color: rgba(0, 0, 0, 0.5);
  transition: opacity 0.3s;
}
.el-upload-list-item-actions-hover {
  display: block;
}
.upload-delete {
  cursor: pointer;
}
/deep/ .el-form-item__content {
  width: 100%;
}
.tab-container {
  overflow: hidden;
}
</style>
